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

Stack trace on syntax error #47

Closed
rjkip opened this issue May 21, 2013 · 13 comments
Closed

Stack trace on syntax error #47

rjkip opened this issue May 21, 2013 · 13 comments

Comments

@rjkip
Copy link

rjkip commented May 21, 2013

When a syntax error occurs, an ErrorException is generated from the shutdown handler. This appears to create an invalid stack trace, as you can see in the image below. Am I doing something wrong or should this issue be addressed?

To circumvent this issue in my application I've temporarily added the option to let ErrorException generate a custom stack trace from its getLine() and getFile() methods.

image

@filp
Copy link
Owner

filp commented May 21, 2013

I believe this might be related to #47, and will have to be addressed. I'll focus on this very very soon.

Thanks for the report! 😄

@filp
Copy link
Owner

filp commented Jun 5, 2013

I'm having some trouble reproducing this one locally; can you provide (if you still have it) the code you were using to cause this issue, and your PHP version?

Cheers!

@rjkip
Copy link
Author

rjkip commented Jun 6, 2013

PHP Version: 5.4.5-1~dotdeb.0
Code to reproduce: https://gist.github.com/rjkip/fa4cfbfbb5fbf5927d75

It appears the bug appears only with the PrettyPageHandler. The JsonResponseHandler outputs this:

{"error":{"type":"Whoops\\Exception\\ErrorException","message":"syntax error, unexpected '}'","file":"\/home\/rkip\/sites\/whoops\/public\/syntax-error.php","line":3}}

While the PrettyPageHandler shows this:

image

@torjusb
Copy link

torjusb commented Jun 6, 2013

I'm having the same issue, running PHP 5.3.3-7+squeeze14.

The issue seems to be related to the following line.
If I were to change the line to the following, it seems to work:

if(false && this->exception instanceof ErrorException && empty($frames[1]['line'])) {

but I assume that will probably break something else.

@rjkip
Copy link
Author

rjkip commented Jun 6, 2013

To clarify things, this happens with any kind of error, e.g. while trying to access a protected property.

@softius
Copy link
Contributor

softius commented Jun 7, 2013

I was to able to fix it by specifying a new method getFrameFromError in Inspector tailored to ErrorException.

See attached. The line however is still reported incorrectly... I suppose further adjustments are needed. @filp please have a look and I can send a Pull request if this looks good.

errorexception

@filp
Copy link
Owner

filp commented Jun 10, 2013

Merged #56, could you guys, if at all possible, verify if it fixes the situation for your specific scenarios? Hopefully it should be a clean fix, but it may need some further adjustments.

Thanks a ton, @softius, and everyone else who helped 😄

@rjkip
Copy link
Author

rjkip commented Jun 10, 2013

Fix confirmed at my end. Thanks a lot!

@filp filp closed this as completed Jun 11, 2013
@mindplay-dk
Copy link

How come there's no "real" stack trace from trapping an ErrorException? I'm having to disable the error-hander temporarily to find out where an error is occurring...

@denis-sokolov
Copy link
Collaborator

@mindplay-dk, I am unable to reproduce your problem, I have a full stack.
What's your Whoops version, what particular error are you trying to trap?
Try with the latest (master) branch of Whoops as well.
Set "filp/whoops": "@dev" in your composer.json file for that.

@mindplay-dk
Copy link

I'm using the last tagged release 1.0.10 with PHP 5.3.8 under Windows.

ErrorException never has a stack trace, at least I've never seen one yet - it doesn't matter which type of warning or notice was trapped.

Might give the master a try tomorrow...

@denis-sokolov
Copy link
Collaborator

Also try and see if there's anything wrong with your PHP, see if the following outputs a correct traceback:

function foo(){
    throw new \ErrorException();
}

try {
    foo();
} catch (\Exception $e) {
    echo $e->getTraceAsString();
}

@mindplay-dk
Copy link

Yep, this no longer occurs with master.

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

No branches or pull requests

6 participants