Bug 918364 - Make exceptions more meaningful in OS.File. r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2013-10-11 11:50:52 -04:00
parent 175a738288
commit e403afd06c
3 changed files with 43 additions and 9 deletions

View File

@ -208,9 +208,16 @@ let Scheduler = {
// Decode any serialized error // Decode any serialized error
if (error instanceof PromiseWorker.WorkerError) { if (error instanceof PromiseWorker.WorkerError) {
throw OS.File.Error.fromMsg(error.data); throw OS.File.Error.fromMsg(error.data);
} else {
throw error;
} }
// Extract something meaningful from WorkerErrorEvent
if (typeof error == "object" && error && error.constructor.name == "WorkerErrorEvent") {
let message = error.message;
if (message == "uncaught exception: [object StopIteration]") {
throw StopIteration;
}
throw new Error(message, error.filename, error.lineno);
}
throw error;
} }
); );
} }
@ -965,14 +972,11 @@ DirectoryIterator.prototype = {
promise = promise.then( promise = promise.then(
DirectoryIterator.Entry.fromMsg, DirectoryIterator.Entry.fromMsg,
function onReject(reason) { function onReject(reason) {
// If the exception is |StopIteration| (which we may determine only if (reason == StopIteration) {
// from its message...) we need to stop the iteration. self.close();
if (!(reason instanceof WorkerErrorEvent && reason.message == "uncaught exception: [object StopIteration]")) { throw StopIteration;
// Any exception other than StopIteration should be propagated as such
throw reason;
} }
self.close(); throw reason;
throw StopIteration;
}); });
return promise; return promise;
}, },

View File

@ -0,0 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
Components.utils.import("resource://gre/modules/osfile.jsm");
function run_test() {
do_test_pending();
run_next_test();
}
add_task(function test_typeerror() {
let exn;
try {
let fd = yield OS.File.open("/tmp", {no_such_key: 1});
do_print("Fd: " + fd);
} catch (ex) {
exn = ex;
}
do_print("Exception: " + exn);
do_check_true(typeof exn == "object");
do_check_true("name" in exn);
do_check_true(exn.message.indexOf("TypeError") != -1);
});
add_task(function() {
do_test_finished();
});

View File

@ -8,5 +8,6 @@ tail =
[test_profiledir.js] [test_profiledir.js]
[test_logging.js] [test_logging.js]
[test_creationDate.js] [test_creationDate.js]
[test_exception.js]
[test_path_constants.js] [test_path_constants.js]
[test_removeDir.js] [test_removeDir.js]