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 committed Aug 19, 2015
1 parent 7055e48 commit 98e67aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 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 @@ -394,13 +394,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/diagnostics/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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 @@ -2233,6 +2234,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
4 changes: 0 additions & 4 deletions tests/standalone/standalone.status
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ javascript_compatibility_errors_test: Skip
javascript_compatibility_warnings_test: Skip
unboxed_int_converter_test: Skip
pair_location_remapping_test: Skip
package/scenarios/invalid/non_existent_packages_file_test: Crash # Issue 24118
package/scenarios/invalid/invalid_utf8_test: Crash # Issue 24120
package/scenarios/invalid/invalid_package_name_test: Crash # Issue 24121
package/scenarios/invalid/same_package_twice_test: Crash # Issue 24122

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

0 comments on commit 98e67aa

Please sign in to comment.