Skip to content

Commit

Permalink
Add stack trace for previous exceptions to bootstrap error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Apr 24, 2023
1 parent c993f0d commit 29827ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/TextUI/Command.php
Expand Up @@ -568,15 +568,30 @@ protected function handleBootstrap(string $filename): void
$this->exitWithErrorMessage($t->getMessage());
}

$this->exitWithErrorMessage(
sprintf(
'Error in bootstrap script: %s:%s%s%s%s',
$message = sprintf(
'Error in bootstrap script: %s:%s%s%s%s',
get_class($t),
PHP_EOL,
$t->getMessage(),
PHP_EOL,
$t->getTraceAsString()
);

while ($t = $t->getPrevious()) {
$message .= sprintf(
'%s%sPrevious error: %s:%s%s%s%s',
PHP_EOL,
PHP_EOL,
get_class($t),
PHP_EOL,
$t->getMessage(),
PHP_EOL,
$t->getTraceAsString()
)
$t->getTraceAsString(),
);
}

$this->exitWithErrorMessage(
$message
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/end-to-end/regression/4620.phpt
Expand Up @@ -19,3 +19,7 @@ PHPUnit %s by Sebastian Bergmann and contributors.
Error in bootstrap script: PHPUnit\TestFixture\MyException:
Big boom. Big bada boom.
%a

Previous error: Exception:
Previous boom.
%a
2 changes: 1 addition & 1 deletion tests/end-to-end/regression/4620/bootstrap.php
Expand Up @@ -15,4 +15,4 @@ final class MyException extends Exception
{
}

throw new MyException('Big boom. Big bada boom.');
throw new MyException('Big boom. Big bada boom.', 0, new Exception('Previous boom.'));

0 comments on commit 29827ea

Please sign in to comment.