Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Error message "SyntaxError: Parse error" doesn't help to find its source #11640

AlexzAK opened this Issue · 4 comments

4 participants


As you know when one of files has invalid syntax PhantomJs provides us just with message:
"SyntaxError: Parse error"

If your file have many lines of if you have multiple files it is painful to search for error cause.
The Jshint tool can help, but it is possible to solve this task using only PhantomJs

if the cpp file src/webpage.cpp at line 160 there is the function javaScriptError

    void javaScriptError(const QString &message, int lineNumber, const QString &sourceID, const QString &stack) {
        emit m_webPage->javaScriptErrorSent(message, stack);

As you can see, arguments lineNumber and sourceID are not used and throwed away.
But them contains valid information about SyntaxError source file and line.
I've check it using debug output

Can you, please, forward arguments lineNumber and sourceID into the javaScriptErrorSent handler and make those arguments available in the javascript onError handler?

It seems that many people find this error message confusing.
It can be far easier to understand and handle error when source of the error is shown


Hmm, that may or may not be true... would have to test it out. While the error signal will fire for a parse error, the error signals are generally geared toward runtime errors, so I wouldn't be surprised if the line number and source ID might be 0 and "" respectively, just like the stack argument is an empty array ([]).

For example:


phantom.onError = function(msg, stack) {
  console.log("FATAL ERROR!\nMessage: " + msg + "\nStack: " + JSON.stringify(stack));





Message: SyntaxError: Parse error
Stack: []

I have added qDebug to the void javaScriptError() and checked that lineNumber and sourceID filled with correct values.
It should work

As you see, SyntaxError occurs not in runtime, but in parse stage. During parsing stack isn't available
And this is the reason why the stack is empty


Thanks for doing the research, @AlexzAK. Yes, this would definitely be an improvement. Several other methods could probably benefit from a similar change as well, e.g. onConsoleMessage, etc.

@vvavrychuk vvavrychuk referenced this issue from a commit in vvavrychuk/phantomjs
@vvavrychuk vvavrychuk fix lack of parse time errors location info
Location information of parse time error is given to javaScriptError not
with stack by with separate lineNumber and sourceID arguments. Put this info
to stack if it is empty so that it will be visible to user.


Does #11784 resolve this issue? Seems to be an issue still in the latest stable.

@ariya ariya removed the API label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.