Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: pkg/dev_compiler/lib/js/legacy/dart_library.js

Issue 2959323002: Improve runtime error when a module is not loaded (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/js/legacy/dart_library.js
diff --git a/pkg/dev_compiler/lib/js/legacy/dart_library.js b/pkg/dev_compiler/lib/js/legacy/dart_library.js
index 89549ae240d6475f998a2f371ab4fc99a8d71436..9c6a376eb12b3a15931ffc07a565e73660efa08a 100644
--- a/pkg/dev_compiler/lib/js/legacy/dart_library.js
+++ b/pkg/dev_compiler/lib/js/legacy/dart_library.js
@@ -67,11 +67,7 @@ dart_library =
loadImports() {
let results = [];
for (let name of this._imports) {
- let lib = libraries.get(name);
- if (!lib) {
- throwLibraryError('Library not available: ' + name);
- }
- results.push(lib.load());
+ results.push(import_(name));
}
return results;
}
@@ -152,12 +148,27 @@ dart_library =
}
dart_library.library = library;
- function import_(libraryName) {
- let loader = libraries.get(libraryName);
- // TODO(vsm): A user might call this directly from JS (as we do in tests).
- // We may want a different error type.
- if (!loader) throwLibraryError('Library not found: ' + libraryName);
- return loader.load();
+ // Maintain a stack of active imports. If a requested library/module is not
+ // available, print the stack to show where/how it was requested.
+ let _stack = [];
+ function import_(name) {
+ let lib = libraries.get(name);
+ if (!lib) {
+ let message = 'Module ' + name + ' not loaded in the browser.';
+ if (_stack != []) {
+ message += '\nDependency via:';
+ let indent = '';
+ for (let last = _stack.length - 1; last >= 0; last--) {
+ indent += ' ';
+ message += '\n' + indent + '- ' + _stack[last];
+ }
+ }
+ throwLibraryError(message);
+ }
+ _stack.push(name);
+ let result = lib.load();
+ _stack.pop();
+ return result;
}
dart_library.import = import_;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698