symfony/process · error · InvalidArgumentException
Expected a failed process, but the given process was…
Error message
Expected a failed process, but the given process was successful.
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at Exception/ProcessFailedException.php:27 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of symfony/process@99b85026db (2026-09-14).
Data as JSON: /api/errors/a6858d97dd197d39.
Report an issue: GitHub.
Appendix: source
Thrown at Exception/ProcessFailedException.php:27
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
use Symfony\Component\Process\Process;
/**
* Exception for failed processes.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ProcessFailedException extends RuntimeException
{
public function __construct(
private Process $process,
) {
if ($process->isSuccessful()) {
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
}
$error = \sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
$process->getCommandLine(),
$process->getExitCode(),
$process->getExitCodeText(),
$process->getWorkingDirectory()
);
if (!$process->isOutputDisabled()) {
$error .= \sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
$process->getOutput(),
$process->getErrorOutput()
);
}
parent::__construct($error);
View on GitHub (pinned to 99b85026db)