page.onError = function (msg, trace) {
var msgStack = ['PHANTOM ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function (t) {
msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function + ')' : ''));
});
}
console.error(msgStack.join('\n'));
phantom.exit(1);
};
In Terminal➜ phantomjs test.js
PHANTOM ERROR: Error: ni chuja
TRACE:
phantomjs://code/test.js:13 in onError
Unfortunately, phantomjs doesn't throw any syntax error, it just hung up. But there is smart way to check syntax.
And results run on your code:
/Users/djaniga/Documents/dawidjaniga/atelier/test.js:7
});};
^
SyntaxError: Unexpected token ;
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:511:25)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:445:3