{"record":{"id":"52f2aca99bcaa6d9","repo":"MahApps/MahApps.Metro","slug":"exit-code-exitcode","errorCode":null,"errorMessage":"Exit code: {exitCode}","messagePattern":"Exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"build.cake","lineNumber":441,"sourceCode":"\n    if (process.GetStandardOutput().Any())\n    {\n      Information($\"Output:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardOutput())}\");\n    }\n\n    if (process.GetStandardError().Any())\n    {\n      // Information($\"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}\");\n      throw new Exception($\"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}\");\n    }\n\n    // This should output 0 as valid arguments supplied\n    var exitCode = process.GetExitCode();\n    Information($\"Exit code: {exitCode}\");\n\n    if (exitCode > 0)\n    {\n      throw new Exception($\"Exit code: {exitCode}\");\n    }\n  }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n// TASK TARGETS\n///////////////////////////////////////////////////////////////////////////////\n\nTask(\"Default\")\n    .IsDependentOn(\"Clean\")\n    .IsDependentOn(\"Restore\")\n    .IsDependentOn(\"StyleXaml\")\n    .IsDependentOn(\"Build\")\n    .IsDependentOn(\"Tests\")\n    ;\n\nTask(\"ci\")\n    .IsDependentOn(\"Default\")","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/build.cake#L423-L459","documentation":"ExecuteProcess (build.cake:436-442) reads the process exit code after the stderr check. If the code is greater than zero it throws an Exception with the numeric code, treating any non-zero return as a build failure. This is the canonical 'tool ran but reported failure' signal.","triggerScenarios":"An external tool invoked through ExecuteProcess exited with a non-zero code (e.g. 1, 2) after the stderr check passed or was already cleared. Common for tools that signal failure only via exit code rather than stderr.","commonSituations":"XAML Styler found unfixable formatting errors and returned 1. Code-signing tool failed authentication against Azure Key Vault. GitVersion failed to compute a version. A tool aborted due to bad arguments or missing input files.","solutions":["Re-run with verbosity increased (Argument(\"verbosity\", Verbosity.Verbose) / -Verbosity=Verbose) so the Output log lines reveal what the tool said before failing.","Cross-reference the numeric exit code with the tool's documentation (e.g. codes from XAML Styler, the signing tool, GitVersion) to find the specific failure.","Fix the input that caused the failure (malformed XAML, wrong signing credentials, missing GitVersion.yml, etc.).","If the tool is transient (network/auth), rerun once the underlying issue is resolved."],"exampleFix":"// before: opaque failure\n./build.ps1 -Target StyleXaml\n// after: get the tool's own output\n./build.ps1 -Target StyleXaml -Verbosity=Verbose\n// then run the tool manually with the same args shown in the log to reproduce","handlingStrategy":"try-catch","validationCode":"// Surface the tool's own output before it exits so the exit code is debuggable\nInformation($\"Running {fileName} {arguments.RenderSafe()}\");\n// after a failure, the Output/Exit code lines in the log pinpoint the cause","typeGuard":null,"tryCatchPattern":"try {\n    ExecuteProcess(tool, args);\n} catch (Exception ex) when (ex.Message.StartsWith(\"Exit code\")) {\n    Error($\"Tool failed: {ex.Message}. Re-run with -Verbosity=Verbose to inspect tool output.\");\n    throw;\n}","preventionTips":["Run failing targets with -Verbosity=Verbose so the tool's stdout/stderr are logged before the exit-code throw.","Reproduce the exact tool invocation manually outside Cake to iterate quickly.","Keep tools pinned to versions whose exit codes you understand.","Validate inputs (files, credentials) before invoking the tool to reduce non-zero exits."],"tags":["build","cake","process","exit-code"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}