Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stack trace for previous exceptions to bootstrap error message #5346

Merged
merged 1 commit into from May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.'));