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

[2.x] Handle all eval() failures from Laravel Tinker #829

Merged
merged 1 commit into from
Feb 18, 2020
Merged

[2.x] Handle all eval() failures from Laravel Tinker #829

merged 1 commit into from
Feb 18, 2020

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Feb 17, 2020

With Laravel Telescope and Laravel Tinker enabled in a project, php artisan tinker and attempt an expression that fatally fails PHP parsing.

Instead of:

$foo[] = 'bar'

Try typing:

foo[] = 'bar'

The desired output would be the below exception about the foo symbol missing $.

In ExecutionLoopClosure.php(55) : eval()'d code line 1:

Cannot use temporary expression in write context

Instead the developer is shown an unrelated Laravel Telescope-related stacktrace:

PHP Warning: file_get_contents(/home/dev/project/vendor/psy/psysh/src/ExecutionLoopClosure.php(55) : eval()'d code): failed to open stream: No such file or directory in
/home/dev/project/vendor/laravel/telescope/src/ExceptionContext.php on line 45

because the watched $exception->getFile() is a human readable string instead of an actual PHP script file path.

This change will show better output by looking for the eval() message string: https://github.com/php/php-src/blob/ac0853eb265784c4238af652de9c54c883ffa99f/Zend/zend_execute.c#L4157

Trying the above example in an automated test won't work since the PHPUnit script exits immediately from the eval() failure. So I've added a case that best mimics how Laravel Tinker / PsySH treat eval() raising ParseError. https://github.com/bobthecow/psysh/blob/29670a13ff363aa83df889d297fc23527a75cfe4/src/ExecutionLoopClosure.php#L95

With Laravel Telescope enabled, it's possible
for some Laravel Tinker expressions to fail
and output a Telescope stacktrace instead of
the original PHP throwable Error.
@driesvints driesvints changed the title Handle all eval() failures from Laravel Tinker [2.x] Handle all eval() failures from Laravel Tinker Feb 18, 2020
@taylorotwell taylorotwell merged commit 14c679b into laravel:2.0 Feb 18, 2020
@derekmd derekmd deleted the handle-eval-syntax-errors branch February 18, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants