{"record":{"id":"3cf690e69ac454d0","repo":"LykosAI/StabilityMatrix","slug":"process-processname-failed-with-exit-code-process-exitcode","errorCode":null,"errorMessage":"Process {processName} failed with exit-code {process.ExitCode}.","messagePattern":"Process (.+?) failed with exit-code (.+?)\\.","errorType":"exception","errorClass":"ProcessException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Processes/ProcessRunner.cs","lineNumber":696,"sourceCode":"        if (!process.HasExited)\n        {\n            await process.WaitForExitAsync(cancelToken).ConfigureAwait(false);\n        }\n\n        if (process.ExitCode == expectedExitCode)\n        {\n            return;\n        }\n\n        // Accessing ProcessName may error on some platforms\n        string? processName = null;\n        try\n        {\n            processName = process.ProcessName;\n        }\n        catch (SystemException) { }\n\n        throw new ProcessException(\n            \"Process \"\n                + (processName == null ? \"\" : processName + \" \")\n                + $\"failed with exit-code {process.ExitCode}.\"\n        );\n    }\n}\n","sourceCodeStart":678,"sourceCodeEnd":703,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Processes/ProcessRunner.cs#L678-L703","documentation":"ProcessRunner.WaitForExitConditionAsync throws ProcessException when the spawned process exits with a non-success (non-zero) exit code. It includes the process name and exit code to identify which external tool failed.","triggerScenarios":"Any child process launched and awaited via ProcessRunner (e.g. python, pip, git, model tools) terminating with a non-zero exit code.","commonSituations":"Missing Python packages, script exceptions, insufficient permissions, bad CLI arguments, out-of-disk during model operations, incompatible environment versions.","solutions":["Read the process's captured stdout/stderr output to see the underlying error message.","Re-run the command manually in a terminal to reproduce and diagnose.","Fix the environment the process runs in (dependencies, paths, permissions).","Handle ProcessException in the caller and surface process output to the user.","Ensure ProcessStartInfo redirects output so diagnostics are available."],"exampleFix":"// before\nawait processRunner.WaitForExitConditionAsync(process); // throws on non-zero exit\n// after\ntry\n{\n    await processRunner.WaitForExitConditionAsync(process);\n}\ncatch (ProcessException ex)\n{\n    _logger.LogError(\"Process failed: {Message}\\nStderr: {Stderr}\", ex.Message, processOutput.Stderr);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"// Verify the executable and environment before launching\nif (!File.Exists( exePath )) throw new FileNotFoundException(\"Executable missing\", exePath);\nif (process.StartInfo.RedirectStandardError == false)\n    process.StartInfo.RedirectStandardError = true; // ensure diagnostics are captured","typeGuard":null,"tryCatchPattern":"try { await processRunner.WaitForExitConditionAsync(process); }\ncatch (ProcessException ex)\n{\n    _logger.LogError(ex, \"Process exited with code {Code}; stderr: {Stderr}\",\n        process.ExitCode, stderrBuilder.ToString());\n    throw;\n}","preventionTips":["Always redirect stdout/stderr so failure output is available for diagnosis","Validate the external environment (python version, packages, paths) before launching","Set working directory and env vars explicitly on ProcessStartInfo","Surface process output to users when a ProcessException occurs","Test child-process commands manually after environment updates"],"tags":["process","exit-code","process-runner"],"backgroundTag":"nonzero-exit-code","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}