Skip to content

Commit 98e67aa

Browse files
dart2js: fail gracefully with invalid package config
Fixes #24118 Fixes #24120 Fixes #24121 Fixes #24122 BUG= R=sigmund@google.com Review URL: https://codereview.chromium.org//1291283006 .
1 parent 7055e48 commit 98e67aa

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/compiler/lib/src/apiimpl.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,17 @@ class Compiler extends leg.Compiler {
394394
}
395395
// The input provider may put a trailing 0 byte when it reads a source
396396
// file, which confuses the package config parser.
397-
if (packageConfigContents.length > 0
398-
&& packageConfigContents.last == 0) {
397+
if (packageConfigContents.length > 0 &&
398+
packageConfigContents.last == 0) {
399399
packageConfigContents = packageConfigContents.sublist(
400400
0, packageConfigContents.length - 1);
401401
}
402402
packages =
403403
new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
404+
}).catchError((error) {
405+
reportError(NO_LOCATION_SPANNABLE, MessageKind.INVALID_PACKAGE_CONFIG,
406+
{'uri': packageConfig, 'exception': error});
407+
packages = Packages.noPackages;
404408
});
405409
} else {
406410
if (packagesDiscoveryProvider == null) {

pkg/compiler/lib/src/diagnostics/messages.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ enum MessageKind {
256256
INVALID_OVERRIDE_METHOD,
257257
INVALID_OVERRIDE_SETTER,
258258
INVALID_OVERRIDE_SETTER_WITH_FIELD,
259+
INVALID_PACKAGE_CONFIG,
259260
INVALID_PACKAGE_URI,
260261
INVALID_PARAMETER,
261262
INVALID_RECEIVER_IN_INITIALIZER,
@@ -2233,6 +2234,13 @@ import '../../Udyn[mic ils/expect.dart';
22332234
main() {}
22342235
"""]),
22352236

2237+
MessageKind.INVALID_PACKAGE_CONFIG:
2238+
const MessageTemplate(MessageKind.INVALID_PACKAGE_CONFIG,
2239+
"""Package config file '#{uri}' is invalid.
2240+
#{exception}""",
2241+
howToFix: DONT_KNOW_HOW_TO_FIX
2242+
),
2243+
22362244
MessageKind.INVALID_PACKAGE_URI:
22372245
const MessageTemplate(MessageKind.INVALID_PACKAGE_URI,
22382246
"'#{uri}' is not a valid package URI (#{exception}).",

tests/standalone/standalone.status

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ javascript_compatibility_errors_test: Skip
100100
javascript_compatibility_warnings_test: Skip
101101
unboxed_int_converter_test: Skip
102102
pair_location_remapping_test: Skip
103-
package/scenarios/invalid/non_existent_packages_file_test: Crash # Issue 24118
104-
package/scenarios/invalid/invalid_utf8_test: Crash # Issue 24120
105-
package/scenarios/invalid/invalid_package_name_test: Crash # Issue 24121
106-
package/scenarios/invalid/same_package_twice_test: Crash # Issue 24122
107103

108104
[ $compiler == dart2js && $jscl ]
109105
assert_test: RuntimeError, OK # Assumes unspecified fields on the AssertionError.

0 commit comments

Comments
 (0)