Skip to content
Permalink
Browse files

Add an exception handler that prints full exception trace (#2418)

By default, php will only print the first few thousand bytes of the
exception, for an uncaught exception
(I think that's the default, and not just my configuration)

Instead, print all of the parts of the exception.

For #1083 (this PR does not cover set_error_handler)
  • Loading branch information
TysonAndre authored and muglug committed Dec 5, 2019
1 parent 6b2c140 commit b713066d32daf8605a3adf826f4873520a31926b
Showing with 20 additions and 0 deletions.
  1. +12 −0 src/Psalm/Internal/exception_handler.php
  2. +2 −0 src/psalm-language-server.php
  3. +2 −0 src/psalm-refactor.php
  4. +2 −0 src/psalm.php
  5. +2 −0 src/psalter.php
@@ -0,0 +1,12 @@
<?php
/**
* If there is an uncaught exception,
* then print more of the backtrace than is done by default to stderr,
* then exit with a non-zero exit code to indicate failure.
*/
set_exception_handler(static function (Throwable $throwable) : void {
fwrite(STDERR, "Uncaught $throwable\n");
$version = defined('PSALM_VERSION') ? PSALM_VERSION : '(unknown version)';
fwrite(STDERR, "(Psalm $version crashed due to an uncaught Throwable)\n");
exit(1);
});
@@ -9,6 +9,8 @@
// show all errors
error_reporting(-1);

require_once __DIR__ . '/Psalm/Internal/exception_handler.php';

$valid_short_options = [
'h',
'v',
@@ -16,6 +16,8 @@
gc_collect_cycles();
gc_disable();

require_once __DIR__ . '/Psalm/Internal/exception_handler.php';

$args = array_slice($argv, 1);

$valid_short_options = ['f:', 'm', 'h', 'r:', 'c:'];
@@ -93,6 +93,8 @@
exit;
}

require_once __DIR__ . '/Psalm/Internal/exception_handler.php';

array_map(
/**
* @param string $arg
@@ -16,6 +16,8 @@
gc_collect_cycles();
gc_disable();

require_once __DIR__ . '/Psalm/Internal/exception_handler.php';

$args = array_slice($argv, 1);

$valid_short_options = ['f:', 'm', 'h', 'r:', 'c:'];

0 comments on commit b713066

Please sign in to comment.
You can’t perform that action at this time.