Skip to content

Commit

Permalink
dart2js: fail gracefully with invalid package config
Browse files Browse the repository at this point in the history
  • Loading branch information
harryterkelsen authored and whesse committed Aug 20, 2015
1 parent 1aecb65 commit 40c76bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/compiler/lib/src/apiimpl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,17 @@ class Compiler extends leg.Compiler {
}
// The input provider may put a trailing 0 byte when it reads a source
// file, which confuses the package config parser.
if (packageConfigContents.length > 0
&& packageConfigContents.last == 0) {
if (packageConfigContents.length > 0 &&
packageConfigContents.last == 0) {
packageConfigContents = packageConfigContents.sublist(
0, packageConfigContents.length - 1);
}
packages =
new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
}).catchError((error) {
reportError(NO_LOCATION_SPANNABLE, MessageKind.INVALID_PACKAGE_CONFIG,
{'uri': packageConfig, 'exception': error});
packages = Packages.noPackages;
});
} else {
if (packagesDiscoveryProvider == null) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/compiler/lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ enum MessageKind {
INVALID_OVERRIDE_METHOD,
INVALID_OVERRIDE_SETTER,
INVALID_OVERRIDE_SETTER_WITH_FIELD,
INVALID_PACKAGE_CONFIG,
INVALID_PACKAGE_URI,
INVALID_PARAMETER,
INVALID_RECEIVER_IN_INITIALIZER,
Expand Down Expand Up @@ -2224,6 +2225,13 @@ import '../../Udyn[mic ils/expect.dart';
main() {}
"""]),

MessageKind.INVALID_PACKAGE_CONFIG:
const MessageTemplate(MessageKind.INVALID_PACKAGE_CONFIG,
"""Package config file '#{uri}' is invalid.
#{exception}""",
howToFix: DONT_KNOW_HOW_TO_FIX
),

MessageKind.INVALID_PACKAGE_URI:
const MessageTemplate(MessageKind.INVALID_PACKAGE_URI,
"'#{uri}' is not a valid package URI (#{exception}).",
Expand Down

0 comments on commit 40c76bb

Please sign in to comment.