Sto avendo difficoltà a capire come PhantomJS gestisce gli errori.PhantomJS la gestione degli errori
Ho un server Apache installato localmente (xampp) e quando visito manualmente "http://localhost/" ottengo il messaggio "Funziona!" pagina.
Come prova, ho scritto un piccolo file (chiamati forceError.js) che causa volutamente un'eccezione incontrollato:
var page = require('webpage').create(),
url = 'http://localhost/';
page.onError = function(msg, trace) {
console.log("page.onError");
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
console.error(msgStack.join('\n'));
};
phantom.onError = function(msg, trace) {
console.log("phantom.onError");
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);
};
page.open(url, function (status) {
console.log("status: " + status);
// an undefined function
thisShouldForceAnError();
});
Quando ho eseguito questo utilizzando:
phantomjs.exe forceError.js
Prima ottengo " status: success "e quindi il processo si blocca. Non vedo né page.onError o phantom.onError invocato.
C'è qualche proprietà o qualcosa che ho bisogno di accendere per ottenere la gestione generale errore?
Sono su Windows 7, PhantomJS la versione 2.0.0, e l'esecuzione di questo nel mio guscio "git bash".
Potrebbe essere un problema con GitHub. Sembra un bug in PhantomJS 2. –
@ArtjomB. Buona idea: https://github.com/lichunqiang/lichunqiang.github.io/issues/13 –
@ArtjomB. grazie: https://github.com/ariya/phantomjs/issues/13403 –