[gjs/wip/ptomato/730101: 2/3] importer: Throw ImportError when module not found
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/730101: 2/3] importer: Throw ImportError when module not found
- Date: Wed, 28 Dec 2016 06:47:45 +0000 (UTC)
commit 6836750f57e8e8a92dc02145b81ccb39ea9304a9
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Dec 27 23:22:46 2016 -0700
importer: Throw ImportError when module not found
If a module is not found in the search path, we now throw an exception
with its name property set to ImportError.
This is so that we can distinguish between the case where there was an
error importing the module (it threw an exception, it had a syntax error,
etc.) and the case where it did not exist. This distinction is important
when importing overrides files.
https://bugzilla.gnome.org/show_bug.cgi?id=730101
gjs/importer.cpp | 3 ++-
installed-tests/js/testImporter.js | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index bd883f3..ce6ee14 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -592,7 +592,8 @@ do_import(JSContext *context,
/* If no exception occurred, the problem is just that we got to the
* end of the path. Be sure an exception is set.
*/
- gjs_throw(context, "No JS module '%s' found in search path", name);
+ gjs_throw_custom(context, "Error", "ImportError",
+ "No JS module '%s' found in search path", name);
}
return result;
diff --git a/installed-tests/js/testImporter.js b/installed-tests/js/testImporter.js
index f2c649a..882b159 100644
--- a/installed-tests/js/testImporter.js
+++ b/installed-tests/js/testImporter.js
@@ -27,8 +27,9 @@ describe('Importer', function () {
expect(imports).toBeDefined();
});
- it('throws an error when trying to import a nonexistent module', function () {
- expect(() => imports.nonexistentModuleName).toThrow();
+ it('throws an import error when trying to import a nonexistent module', function () {
+ expect(() => imports.nonexistentModuleName)
+ .toThrow(jasmine.objectContaining({ name: 'ImportError' }));
});
it('throws an error when evaluating the module file throws an error', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]