ProcessStartFailedException.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Process\Exception;
  11. use Symfony\Component\Process\Process;
  12. /**
  13. * Exception for processes failed during startup.
  14. */
  15. class ProcessStartFailedException extends ProcessFailedException
  16. {
  17. public function __construct(
  18. private Process $process,
  19. ?string $message,
  20. ) {
  21. if ($process->isStarted()) {
  22. throw new InvalidArgumentException('Expected a process that failed during startup, but the given process was started successfully.');
  23. }
  24. $error = \sprintf('The command "%s" failed.'."\n\nWorking directory: %s\n\nError: %s",
  25. $process->getCommandLine(),
  26. $process->getWorkingDirectory(),
  27. $message ?? 'unknown'
  28. );
  29. // Skip parent constructor
  30. RuntimeException::__construct($error);
  31. }
  32. public function getProcess(): Process
  33. {
  34. return $this->process;
  35. }
  36. }