Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Unified Diff: pkg/front_end/lib/memory_file_system.dart

Issue 2864183002: Throw FileSystemException from FileSystemEntity methods. (Closed)
Patch Set: Use OS error message if available. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/file_system.dart ('k') | pkg/front_end/lib/physical_file_system.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/memory_file_system.dart
diff --git a/pkg/front_end/lib/memory_file_system.dart b/pkg/front_end/lib/memory_file_system.dart
index 6c57167a87d45e1620fadab02a82fe585658256d..f53f24a8632bfe875f00a81f20e9cbb8d72520fd 100644
--- a/pkg/front_end/lib/memory_file_system.dart
+++ b/pkg/front_end/lib/memory_file_system.dart
@@ -67,32 +67,36 @@ class MemoryFileSystemEntity implements FileSystemEntity {
identical(other._fileSystem, _fileSystem);
@override
- Future<List<int>> readAsBytes() async {
- List<int> contents = _fileSystem._files[uri];
- if (contents != null) {
- return contents.toList();
- }
- throw new Exception('File does not exist');
- }
-
- @override
- Future<String> readAsString() async {
- List<int> contents = await readAsBytes();
- return UTF8.decode(contents);
- }
-
- @override
Future<bool> exists() async => _fileSystem._files[uri] != null;
@override
Future<DateTime> lastModified() async {
var lastModified = _fileSystem._lastModified[uri];
if (lastModified == null) {
- throw new Exception('File does not exist');
+ throw new FileSystemException(uri, 'File $uri does not exist.');
}
return lastModified;
}
+ @override
+ Future<List<int>> readAsBytes() async {
+ List<int> contents = _fileSystem._files[uri];
+ if (contents == null) {
+ throw new FileSystemException(uri, 'File $uri does not exist.');
+ }
+ return contents.toList();
+ }
+
+ @override
+ Future<String> readAsString() async {
+ List<int> bytes = await readAsBytes();
+ try {
+ return UTF8.decode(bytes);
+ } on FormatException catch (e) {
+ throw new FileSystemException(uri, e.message);
+ }
+ }
+
/// Writes the given raw bytes to this file system entity.
///
/// If no file exists, one is created. If a file exists already, it is
« no previous file with comments | « pkg/front_end/lib/file_system.dart ('k') | pkg/front_end/lib/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698