Bug 749258: Have toolkit/devtools/debugger xpcshell tests register a listener for Components.utils.reportError, so tests fail when they throw an exception. r=past

This commit is contained in:
Jim Blandy 2012-05-01 15:29:48 -07:00
Родитель 8b6cd6b2c0
Коммит 433ec64664
3 изменённых файлов: 66 добавлений и 6 удалений

Просмотреть файл

@ -375,10 +375,10 @@ DebuggerClient.prototype = {
*/ */
request: function DC_request(aRequest, aOnResponse) { request: function DC_request(aRequest, aOnResponse) {
if (!this._connected) { if (!this._connected) {
throw "Have not yet received a hello packet from the server."; throw Error("Have not yet received a hello packet from the server.");
} }
if (!aRequest.to) { if (!aRequest.to) {
throw "Request packet has no destination."; throw Error("Request packet has no destination.");
} }
this._pendingRequests.push({ to: aRequest.to, this._pendingRequests.push({ to: aRequest.to,
@ -449,7 +449,7 @@ DebuggerClient.prototype = {
onResponse(aPacket); onResponse(aPacket);
} }
} catch(ex) { } catch(ex) {
dumpn("Error handling response: " + ex + " - " + ex.stack); dumpn("Error handling response: " + ex + " - stack:\n" + ex.stack);
Cu.reportError(ex); Cu.reportError(ex);
} }
@ -536,7 +536,7 @@ ThreadClient.prototype = {
_assertPaused: function TC_assertPaused(aCommand) { _assertPaused: function TC_assertPaused(aCommand) {
if (!this.paused) { if (!this.paused) {
throw aCommand + " command sent while not paused."; throw Error(aCommand + " command sent while not paused.");
} }
}, },

Просмотреть файл

@ -63,6 +63,17 @@ function dbg_assert(cond, e) {
} }
} }
/* Turn the error e into a string, without fail. */
function safeErrorString(aError) {
try {
var s = aError.toString();
if (typeof s === "string")
return s;
} catch (ee) { }
return "<failed trying to find error description>";
}
loadSubScript.call(this, "chrome://global/content/devtools/dbg-transport.js"); loadSubScript.call(this, "chrome://global/content/devtools/dbg-transport.js");
// XPCOM constructors // XPCOM constructors
@ -445,11 +456,14 @@ DebuggerServerConnection.prototype = {
} catch(e) { } catch(e) {
Cu.reportError(e); Cu.reportError(e);
ret = { error: "unknownError", ret = { error: "unknownError",
message: "An unknown error has occurred while processing request." }; message: ("error occurred while processing '" + aPacket.type +
"' request: " + safeErrorString(e)) };
} }
} else { } else {
ret = { error: "unrecognizedPacketType", ret = { error: "unrecognizedPacketType",
message: 'Actor "' + actor.actorID + '" does not recognize the packet type "' + aPacket.type + '"' }; message: ('Actor "' + actor.actorID +
'" does not recognize the packet type "' +
aPacket.type + '"') };
} }
if (!ret) { if (!ret) {

Просмотреть файл

@ -16,6 +16,52 @@ Services.prefs.setBoolPref("devtools.debugger.log", true);
Cu.import("resource:///modules/devtools/dbg-server.jsm"); Cu.import("resource:///modules/devtools/dbg-server.jsm");
Cu.import("resource:///modules/devtools/dbg-client.jsm"); Cu.import("resource:///modules/devtools/dbg-client.jsm");
// Convert an nsIScriptError 'aFlags' value into an appropriate string.
function scriptErrorFlagsToKind(aFlags) {
var kind;
if (aFlags & Ci.nsIScriptError.warningFlag)
kind = "warning";
if (aFlags & Ci.nsIScriptError.exceptionFlag)
kind = "exception";
else
kind = "error";
if (aFlags & Ci.nsIScriptError.strictFlag)
kind = "strict " + kind;
return kind;
}
// Register a console listener, so console messages don't just disappear
// into the ether.
let errorCount = 0;
let listener = {
observe: function (aMessage) {
errorCount++;
try {
// If we've been given an nsIScriptError, then we can print out
// something nicely formatted, for tools like Emacs to pick up.
var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
scriptErrorFlagsToKind(aMessage.flags) + ": " +
aMessage.errorMessage + "\n");
var string = aMessage.errorMessage;
} catch (x) {
// Be a little paranoid with message, as the whole goal here is to lose
// no information.
try {
var string = "" + aMessage.message;
} catch (x) {
var string = "<error converting error message to string>";
}
}
do_throw("head_dbg.js got console message: " + string + "\n");
}
};
let consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
consoleService.registerListener(listener);
function check_except(func) function check_except(func)
{ {