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
if (error instanceof PromiseWorker.WorkerError) {
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(
DirectoryIterator.Entry.fromMsg,
function onReject(reason) {
// If the exception is |StopIteration| (which we may determine only
// from its message...) we need to stop the iteration.
if (!(reason instanceof WorkerErrorEvent && reason.message == "uncaught exception: [object StopIteration]")) {
// Any exception other than StopIteration should be propagated as such
throw reason;
if (reason == StopIteration) {
self.close();
throw StopIteration;
}
self.close();
throw StopIteration;
throw reason;
});
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_logging.js]
[test_creationDate.js]
[test_exception.js]
[test_path_constants.js]
[test_removeDir.js]