Error message "SyntaxError: Parse error" doesn't help to find its source #11640
Comments
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 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:
|
I have added As you see, SyntaxError occurs not in runtime, but in parse stage. During parsing stack isn't available |
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. |
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
Does #11784 resolve this issue? Seems to be an issue still in the latest stable. |
i have current issue |
Fixed in 2.0. Please upgrade to PhantomJS 2.0. |
Just downloaded phantom.js v 2.1.1 and now syntax error causes phantom to stop responding. No error message at all. |
@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. |
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
As you can see, arguments
lineNumber
andsourceID
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
andsourceID
into thejavaScriptErrorSent
handler and make those arguments available in the javascriptonError
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
The text was updated successfully, but these errors were encountered: