MahApps/MahApps.Metro · error · Exception

Exit code: {exitCode}

Error message

Exit code: {exitCode}

What it means

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.

Source

Thrown at build.cake:441

    if (process.GetStandardOutput().Any())
    {
      Information($"Output:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardOutput())}");
    }

    if (process.GetStandardError().Any())
    {
      // Information($"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}");
      throw new Exception($"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}");
    }

    // This should output 0 as valid arguments supplied
    var exitCode = process.GetExitCode();
    Information($"Exit code: {exitCode}");

    if (exitCode > 0)
    {
      throw new Exception($"Exit code: {exitCode}");
    }
  }
}

///////////////////////////////////////////////////////////////////////////////
// TASK TARGETS
///////////////////////////////////////////////////////////////////////////////

Task("Default")
    .IsDependentOn("Clean")
    .IsDependentOn("Restore")
    .IsDependentOn("StyleXaml")
    .IsDependentOn("Build")
    .IsDependentOn("Tests")
    ;

Task("ci")
    .IsDependentOn("Default")

View on GitHub (pinned to 72099e310b)

Solutions

  1. Re-run with verbosity increased (Argument("verbosity", Verbosity.Verbose) / -Verbosity=Verbose) so the Output log lines reveal what the tool said before failing.
  2. 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.
  3. Fix the input that caused the failure (malformed XAML, wrong signing credentials, missing GitVersion.yml, etc.).
  4. If the tool is transient (network/auth), rerun once the underlying issue is resolved.

Example fix

// before: opaque failure
./build.ps1 -Target StyleXaml
// after: get the tool's own output
./build.ps1 -Target StyleXaml -Verbosity=Verbose
// then run the tool manually with the same args shown in the log to reproduce
Defensive patterns

Strategy: try-catch

Validate before calling

// Surface the tool's own output before it exits so the exit code is debuggable
Information($"Running {fileName} {arguments.RenderSafe()}");
// after a failure, the Output/Exit code lines in the log pinpoint the cause

Try / catch

try {
    ExecuteProcess(tool, args);
} catch (Exception ex) when (ex.Message.StartsWith("Exit code")) {
    Error($"Tool failed: {ex.Message}. Re-run with -Verbosity=Verbose to inspect tool output.");
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13). Data as JSON: /api/errors/52f2aca99bcaa6d9. Report an issue: GitHub.