ProcessStartFailedException.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. private Process $process;
  18. public function __construct(Process $process, ?string $message)
  19. {
  20. if ($process->isStarted()) {
  21. throw new InvalidArgumentException('Expected a process that failed during startup, but the given process was started successfully.');
  22. }
  23. $error = sprintf('The command "%s" failed.'."\n\nWorking directory: %s\n\nError: %s",
  24. $process->getCommandLine(),
  25. $process->getWorkingDirectory(),
  26. $message ?? 'unknown'
  27. );
  28. // Skip parent constructor
  29. RuntimeException::__construct($error);
  30. $this->process = $process;
  31. }
  32. public function getProcess(): Process
  33. {
  34. return $this->process;
  35. }
  36. }