{"record":{"id":"80b32d207154563a","repo":"RicoSuter/NSwag","slug":"unknown-error","errorCode":null,"errorMessage":"Unknown error","messagePattern":"Unknown error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/NSwag.Npm/bin/nswag.js","lineNumber":96,"sourceCode":"else if (runtimeIndices.length === 1) {\n    args.splice(runtimeIndices[0], 1);\n}\n\nif (runtimeValue) {\n    if (runtimeValue.toLowerCase() === \"netcore\") {\n\n        // detect latest installed NetCore Version\n        console.log(\"Trying to detect latest installed NetCore Version.\");\n        var infoCmd = \"dotnet\";\n        var infoArgs = [\"--version\"];\n\n        try {\n            var result = c.spawnSync(infoCmd, infoArgs, { encoding: 'utf8' });\n            if (result.error) {\n                throw result.error;\n            }\n            if (result.status !== 0) {\n                throw new Error(result.stderr ? result.stderr.toString() : \"Unknown error\");\n            }\n            var coreVersion = result.stdout.trim();\n            const version = supportedCoreVersions.find(v => coreVersion.startsWith(v.ver));\n            if (!version) {\n                console.error(\"Error: Detected .NET Core version '\" + coreVersion + \"' is not supported.\");\n                process.exit(1);\n            }\n            console.log(\"Using supported .NET Core version: \" + version.dir);\n            runtimeValue = version.dir;\n        } catch (error) {\n            console.error(\"Error: Could not detect .NET Core version.\");\n            console.debug(error);\n            process.exit(1);\n        }\n    }\n\n    if (!runtimeValue.toLowerCase().startsWith(\"win\")) {\n        const isSupported = supportedCoreVersions.some(v => v.dir.toLowerCase() === runtimeValue.toLowerCase());","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Npm/bin/nswag.js#L78-L114","documentation":"nswag.js runs 'dotnet --info' (spawnSync) to detect the installed .NET Core version before launching the NSwag command host. If the spawn itself failed it rethrows that error; if dotnet ran but exited non-zero with an empty stderr, the script throws new Error(\"Unknown error\"). This means the .NET runtime probe failed without a diagnostic message.","triggerScenarios":"Running the nswag npm CLI on a machine where 'dotnet --info' exits non-zero (broken or partially uninstalled .NET SDK, corrupted installation, permission issues), where stderr is empty so no better message can be surfaced.","commonSituations":"CI containers without the .NET SDK installed or with only the runtime; dotnet on PATH but a broken multi-level-lookup/globaljson setup; antivirus or permissions killing dotnet; incompatible SDK version left after an upgrade; PATH pointing to a shim that fails.","solutions":["Run 'dotnet --info' manually in the same shell to see the real failure and fix the .NET SDK installation (reinstall from https://dotnet.microsoft.com).","Ensure the dotnet executable is on PATH and functional for the user running nswag.","In CI, use a setup step (e.g. actions/setup-dotnet) to install a supported .NET Core SDK before running nswag.","Check for a global.json pinning an SDK version that is not installed, and remove or correct it.","Upgrade the @nswag/npm package so its supportedCoreVersions list matches your installed .NET version, avoiding the related 'not supported' exit path."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before invoking nswag CLI, probe dotnet yourself\nconst { spawnSync } = require('child_process');\nconst r = spawnSync('dotnet', ['--info'], { encoding: 'utf8' });\nif (r.error || r.status !== 0) {\n  console.error('dotnet CLI is broken or missing; install the .NET SDK first');\n  process.exit(1);\n}","typeGuard":"function isDotnetAvailable() {\n  const r = require('child_process').spawnSync('dotnet', ['--info'], { encoding: 'utf8' });\n  return !r.error && r.status === 0;\n}","tryCatchPattern":"try {\n  execSync('npx nswag run nswag.json');\n} catch (err) {\n  if (String(err.message).includes('Unknown error')) {\n    console.error('nswag failed to probe dotnet; verify \"dotnet --info\" works manually');\n  }\n  process.exit(1);\n}","preventionTips":["Install and verify the .NET SDK ('dotnet --info' exits 0) in every environment that runs nswag.","In CI, add an official setup-dotnet step before running nswag.","Keep @nswag/npm updated so its supported .NET version list matches your SDK.","Check global.json does not pin an SDK version that is not installed."],"tags":["nodejs","dotnet","cli","process-spawn"],"backgroundTag":"cli-command-failed","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}