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

Unified Diff: runtime/bin/builtin.dart

Issue 1822863002: - Properly return null if an unknown package is resolved. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments. Created 4 years, 9 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 | tests/isolate/scenarios/bad_resolve_package/.packages » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/builtin.dart
diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart
index 9a34b51cb0b4c31a7ae682b7637966357b81c124..2f64b77be680e432168a986bfa4da67f48d16b48 100644
--- a/runtime/bin/builtin.dart
+++ b/runtime/bin/builtin.dart
@@ -295,7 +295,18 @@ Uri _resolvePackageUri(Uri uri) {
if (mapping == null) {
throw "No mapping for '$packageName' package when resolving '$uri'.";
}
- var path = uri.path.substring(packageName.length + 1);
+ var path;
+ if (uri.path.length > packageName.length) {
+ path = uri.path.substring(packageName.length + 1);
+ } else {
+ // Handle naked package resolution to the default package name:
+ // package:foo is equivalent to package:foo/foo.dart
+ assert(uri.path.length == packageName.length);
+ path = "$packageName.dart";
Lasse Reichstein Nielsen 2016/03/23 11:18:18 While I like this change in general, it should be
+ }
+ if (_traceLoading) {
+ _log("Path to be resolved in package: $path");
+ }
resolvedUri = mapping.resolve(path);
}
if (_traceLoading) {
@@ -754,7 +765,17 @@ Future<Uri> _resolvePackageUriFuture(Uri packageUri) async {
}
assert(_packagesReady);
- var result = _resolvePackageUri(packageUri);
+ var result;
+ try {
+ result = _resolvePackageUri(packageUri);
+ } catch (e, s) {
+ // Any error during resolution will resolve this package as not mapped,
+ // which is indicated by a null return.
+ if (_traceLoading) {
+ _log("Exception ($e) when resolving package URI: $packageUri");
+ }
+ result = null;
+ }
if (_traceLoading) {
_log("Resolved '$packageUri' to '$result'");
}
« no previous file with comments | « no previous file | tests/isolate/scenarios/bad_resolve_package/.packages » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698