Skip to content

Commit 40c76bb

Browse files
harryterkelsenwhesse
authored andcommitted
dart2js: fail gracefully with invalid package config
Fixes #24118 Fixes #24120 Fixes #24121 Fixes #24122 BUG= [email protected] Review URL: https://codereview.chromium.org//1291283006 .
1 parent 1aecb65 commit 40c76bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/compiler/lib/src/apiimpl.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,17 @@ class Compiler extends leg.Compiler {
381381
}
382382
// The input provider may put a trailing 0 byte when it reads a source
383383
// file, which confuses the package config parser.
384-
if (packageConfigContents.length > 0
385-
&& packageConfigContents.last == 0) {
384+
if (packageConfigContents.length > 0 &&
385+
packageConfigContents.last == 0) {
386386
packageConfigContents = packageConfigContents.sublist(
387387
0, packageConfigContents.length - 1);
388388
}
389389
packages =
390390
new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
391+
}).catchError((error) {
392+
reportError(NO_LOCATION_SPANNABLE, MessageKind.INVALID_PACKAGE_CONFIG,
393+
{'uri': packageConfig, 'exception': error});
394+
packages = Packages.noPackages;
391395
});
392396
} else {
393397
if (packagesDiscoveryProvider == null) {

pkg/compiler/lib/src/warnings.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ enum MessageKind {
252252
INVALID_OVERRIDE_METHOD,
253253
INVALID_OVERRIDE_SETTER,
254254
INVALID_OVERRIDE_SETTER_WITH_FIELD,
255+
INVALID_PACKAGE_CONFIG,
255256
INVALID_PACKAGE_URI,
256257
INVALID_PARAMETER,
257258
INVALID_RECEIVER_IN_INITIALIZER,
@@ -2224,6 +2225,13 @@ import '../../Udyn[mic ils/expect.dart';
22242225
main() {}
22252226
"""]),
22262227

2228+
MessageKind.INVALID_PACKAGE_CONFIG:
2229+
const MessageTemplate(MessageKind.INVALID_PACKAGE_CONFIG,
2230+
"""Package config file '#{uri}' is invalid.
2231+
#{exception}""",
2232+
howToFix: DONT_KNOW_HOW_TO_FIX
2233+
),
2234+
22272235
MessageKind.INVALID_PACKAGE_URI:
22282236
const MessageTemplate(MessageKind.INVALID_PACKAGE_URI,
22292237
"'#{uri}' is not a valid package URI (#{exception}).",

0 commit comments

Comments
 (0)