Index: pkg/front_end/lib/src/fasta/translate_uri.dart |
diff --git a/pkg/front_end/lib/src/fasta/translate_uri.dart b/pkg/front_end/lib/src/fasta/translate_uri.dart |
index 429a65730bc11d336800761c5dadcf4f1fce79d7..37d98eeb3ca6998dac354f03a84c42f346f82848 100644 |
--- a/pkg/front_end/lib/src/fasta/translate_uri.dart |
+++ b/pkg/front_end/lib/src/fasta/translate_uri.dart |
@@ -6,10 +6,14 @@ library fasta.translate_uri; |
import 'dart:async' show Future; |
-import 'dart:io' show File; |
- |
import 'package:package_config/packages_file.dart' as packages_file show parse; |
+import 'errors.dart' show inputError; |
+ |
+import 'io.dart' show readBytesFromFile; |
+ |
+import 'scanner/characters.dart' show $LF; |
+ |
class TranslateUri { |
final Map<String, Uri> packages; |
final Map<String, Uri> dartLibraries; |
@@ -74,9 +78,16 @@ class TranslateUri { |
}; |
} |
uri ??= Uri.base.resolve(".packages"); |
- File file = new File.fromUri(uri); |
- List<int> bytes = await file.readAsBytes(); |
- Map<String, Uri> packages = packages_file.parse(bytes, uri); |
+ List<int> bytes = await readBytesFromFile(uri); |
+ Map<String, Uri> packages = const <String, Uri>{}; |
+ try { |
+ // We always add an extra zero byte at the end of files. We change that |
+ // to a newline to avoid a format error from `packages_file.parse`. |
+ bytes[bytes.length - 1] = $LF; |
+ packages = packages_file.parse(bytes, uri); |
+ } on FormatException catch (e) { |
+ return inputError(uri, e.offset, e.message); |
+ } |
return new TranslateUri(packages, dartLibraries); |
} |
} |