{"record":{"id":"e31b9ba9256396b0","repo":"MahApps/MahApps.Metro","slug":"errors-occurred-environment-newline-string-join","errorCode":null,"errorMessage":"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}","messagePattern":"Errors occurred:(.+?) (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"build.cake","lineNumber":432,"sourceCode":"  {\n    processSettings.WorkingDirectory = workingDirectory;\n  }\n\n  Information($\"Arguments: {arguments.RenderSafe()}\");\n\n  using(var process = StartAndReturnProcess(fileName, processSettings))\n  {\n    process.WaitForExit();\n\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\")","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/build.cake#L414-L450","documentation":"Inside ExecuteProcess (build.cake:429-433), after the external process exits the build checks whether anything was written to standard error. If process.GetStandardError() contains any line, it throws an Exception joining all stderr lines, regardless of the exit code. This is stricter than exit-code checking: even a tool that returns 0 will fail the build if it prints to stderr.","triggerScenarios":"Any tool invoked via ExecuteProcess writes one or more lines to stderr — a warning, a deprecation notice, or a genuine error. The check fires before the exit code is examined, so even successful runs that emit stderr are treated as failures.","commonSituations":"XAML Styler or another tool emits a warning/notice to stderr on success. A newer version of a tool started writing verbose diagnostics to stderr. Code-signing tool emits status text to stderr. Cross-platform tooling differences where Windows writes to stdout but the same tool writes to stderr elsewhere.","solutions":["Inspect the captured stderr in the exception message to see exactly what the tool reported; address the root cause the tool is complaining about.","If the stderr is benign (warnings/notices), downgrade the tool to a version that does not write to stderr on success, or pass a flag that silences verbose/diagnostic output.","Reconfigure the tool to write diagnostics to stdout or a log file instead of stderr.","If you control build.cake, consider distinguishing fatal errors from warnings rather than treating all stderr as failure."],"exampleFix":"// before: any stderr line fails the build\nif (process.GetStandardError().Any())\n{\n    throw new Exception($\"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}\");\n}\n// after: only fail on non-zero exit code, log stderr as warning\nvar stderr = process.GetStandardError();\nif (stderr.Any())\n{\n    Warning($\"Stderr from {fileName}:{Environment.NewLine}{string.Join(Environment.NewLine, stderr)}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// When wrapping ExecuteProcess, capture the stderr text and decide whether it is fatal\ntry {\n    ExecuteProcess(styler, args);\n} catch (Exception ex) when (ex.Message.StartsWith(\"Errors occurred\")) {\n    if (IsBenignStderr(ex.Message)) { Warning($\"Tool emitted stderr: {ex.Message}\"); }\n    else throw;\n}","preventionTips":["When you control the tool, configure it to write only errors (not warnings/notices) to stderr.","Pin tool versions known to not write diagnostics to stderr on success.","Prefer treating exit code as the source of truth; route stderr to the log and only fail on non-zero codes.","When authoring a build helper, separate fatal stderr from informational stderr."],"tags":["build","cake","process","stderr","diagnostics"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}