Skip to content

Commit 2af22fe

Browse files
committed
Refactor error handling in RunCommand to make exception templating of message indistinguishable from native php type error.
1 parent 7b93ae7 commit 2af22fe

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/Command/RunCommand.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,26 @@ public function execute(array $args, $outputStream = STDOUT, $errorStream = STDE
4242
return 1;
4343
}
4444

45-
TypePHP::boot();
46-
require realpath($target);
45+
try {
46+
TypePHP::boot();
47+
$realTarget = realpath($target);
48+
if ($realTarget !== false) {
49+
require $realTarget;
50+
}
51+
} catch (\Throwable $e) {
52+
$class = \get_class($e);
53+
$file = $e->getFile();
54+
$line = $e->getLine();
55+
$msg = $e->getMessage();
56+
57+
fwrite($errorStream, "PHP Fatal error: Uncaught {$class}: {$msg} in {$file} on line {$line}\n");
58+
fwrite($errorStream, "Stack trace:\n");
59+
fwrite($errorStream, "#0 {main}\n");
60+
fwrite($errorStream, " thrown in {$file} on line {$line}\n");
61+
62+
return 255;
63+
}
4764

4865
return 0;
4966
}
50-
}
67+
}

0 commit comments

Comments
 (0)