Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

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

Closed
AlexzAK opened this issue Sep 24, 2013 · 8 comments
Closed

Comments

@AlexzAK
Copy link

AlexzAK commented Sep 24, 2013

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) {
        Q_UNUSED(lineNumber);
        Q_UNUSED(sourceID);
        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

So,
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

@JamesMGreene
Copy link
Collaborator

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:

Code:

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

phantom.injectJs("parseError.js");

console.log("Injected.");

phantom.exit();

Result:

FATAL ERROR!
Message: SyntaxError: Parse error
Stack: []

@AlexzAK
Copy link
Author

AlexzAK commented Sep 25, 2013

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

@JamesMGreene
Copy link
Collaborator

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 added a commit to vvavrychuk/phantomjs that referenced this issue Nov 23, 2013
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.

ariya#11640
@shellscape
Copy link

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

@ariya ariya removed the API label Feb 1, 2015
@a-x-
Copy link

a-x- commented Dec 8, 2015

i have current issue

@vitallium
Copy link
Collaborator

Fixed in 2.0. Please upgrade to PhantomJS 2.0.

@mao73a
Copy link

mao73a commented Jul 18, 2017

Just downloaded phantom.js v 2.1.1 and now syntax error causes phantom to stop responding. No error message at all.

@shellscape
Copy link

@mao73a normally I wouldn't suggest another project, but given that the last maintainer has stepped down (https://www.infoq.com/news/2017/04/Phantomjs-future-uncertain) and this project won't be maintained anymore, I'd suggest using Headless Chrome (check out the chromy module) or Electron.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants