{"record":{"id":"a6858d97dd197d39","repo":"symfony/process","slug":"expected-a-failed-process-but-the-given-process-was","errorCode":null,"errorMessage":"Expected a failed process, but the given process was successful.","messagePattern":"Expected a failed process, but the given process was successful\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Exception/ProcessFailedException.php","lineNumber":27,"sourceCode":" * file that was distributed with this source code.\n */\n\nnamespace Symfony\\Component\\Process\\Exception;\n\nuse Symfony\\Component\\Process\\Process;\n\n/**\n * Exception for failed processes.\n *\n * @author Johannes M. Schmitt <schmittjoh@gmail.com>\n */\nclass ProcessFailedException extends RuntimeException\n{\n    public function __construct(\n        private Process $process,\n    ) {\n        if ($process->isSuccessful()) {\n            throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');\n        }\n\n        $error = \\sprintf('The command \"%s\" failed.'.\"\\n\\nExit Code: %s(%s)\\n\\nWorking directory: %s\",\n            $process->getCommandLine(),\n            $process->getExitCode(),\n            $process->getExitCodeText(),\n            $process->getWorkingDirectory()\n        );\n\n        if (!$process->isOutputDisabled()) {\n            $error .= \\sprintf(\"\\n\\nOutput:\\n================\\n%s\\n\\nError Output:\\n================\\n%s\",\n                $process->getOutput(),\n                $process->getErrorOutput()\n            );\n        }\n\n        parent::__construct($error);\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Exception/ProcessFailedException.php#L9-L45","documentation":"A guard thrown from ProcessFailedException::__construct: this exception may only wrap a Process that has actually terminated unsuccessfully. Passing a successful (exit code 0) Process is a caller programming error, so an InvalidArgumentException is raised before the exception object is built.","triggerScenarios":"Thrown at Exception/ProcessFailedException.php:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check $process->isSuccessful() before constructing ProcessFailedException","Only construct this exception from catch blocks or after wait()/run() reports failure","Use getProcess()->isSuccessful() to branch instead of relying on the exception constructor"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"99b85026db14a68f02c6f3eeb01a1170ca25c491","analyzedAt":"2026-09-14T11:23:33.683Z","contentChangedAt":"2026-09-14T11:23:33.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}