fix!: handle errors properly

This commit is contained in:
2026-02-14 20:49:08 +01:00
parent 5797059008
commit bd065eab32
6 changed files with 103 additions and 39 deletions

View File

@@ -278,6 +278,8 @@ final class Command implements Stringable
* Executes the command as a child process, returning a handle to it.
*
* By default, stdin, stdout and stderr are inherited from the parent.
*
* @throws ChildException
*/
public function spawn(): Child
{
@@ -299,6 +301,8 @@ final class Command implements Stringable
* collecting its status.
*
* By default, stdin, stdout and stderr are inherited from the parent.
*
* @throws ChildException
*/
public function status(): ExitStatus
{
@@ -311,6 +315,8 @@ final class Command implements Stringable
*
* By default, stdout and stderr are captured (and used to provide the
* resulting output). Stdin is not inherited from the parent.
*
* @throws ChildException
*/
public function output(): Output
{
@@ -396,13 +402,6 @@ final class Command implements Stringable
}
}
if (!is_executable($program)) {
throw new CommandException(sprintf(
'Program "%s" is not executable',
$program,
));
}
// Handle environment inheritance.
$environment = $this->environment;
if (is_array($environment) && $this->environmentInherit) {
@@ -414,7 +413,7 @@ final class Command implements Stringable
}
try {
set_error_handler(CommandException::handleError(...));
set_error_handler(ChildException::handleError(...));
$proc = proc_open(
[$program, ...$this->args],
$descriptorSpec,