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

Unified Diff: pkg/front_end/lib/physical_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/memory_file_system.dart ('k') | pkg/front_end/lib/src/fasta/source/source_loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/physical_file_system.dart
diff --git a/pkg/front_end/lib/physical_file_system.dart b/pkg/front_end/lib/physical_file_system.dart
index a81a44dfea7c9850aebde4edd92e6e6e8543aa54..59402a322e01b50b2bcae0e565046a482b09c163 100644
--- a/pkg/front_end/lib/physical_file_system.dart
+++ b/pkg/front_end/lib/physical_file_system.dart
@@ -43,12 +43,6 @@ class _PhysicalFileSystemEntity implements FileSystemEntity {
other is _PhysicalFileSystemEntity && other.uri == uri;
@override
- Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes();
-
- @override
- Future<String> readAsString() => new io.File.fromUri(uri).readAsString();
-
- @override
Future<bool> exists() async {
if (await io.FileSystemEntity.isFile(uri.toFilePath())) {
return new io.File.fromUri(uri).exists();
@@ -58,5 +52,41 @@ class _PhysicalFileSystemEntity implements FileSystemEntity {
}
@override
- Future<DateTime> lastModified() => new io.File.fromUri(uri).lastModified();
+ Future<DateTime> lastModified() async {
+ try {
+ return await new io.File.fromUri(uri).lastModified();
+ } on io.FileSystemException catch (exception) {
+ throw _toFileSystemException(exception);
+ }
+ }
+
+ @override
+ Future<List<int>> readAsBytes() async {
+ try {
+ return await new io.File.fromUri(uri).readAsBytes();
+ } on io.FileSystemException catch (exception) {
+ throw _toFileSystemException(exception);
+ }
+ }
+
+ @override
+ Future<String> readAsString() async {
+ try {
+ return await new io.File.fromUri(uri).readAsString();
+ } on io.FileSystemException catch (exception) {
+ throw _toFileSystemException(exception);
+ }
+ }
+
+ /**
+ * Return the [FileSystemException] for the given I/O exception.
+ */
+ FileSystemException _toFileSystemException(io.FileSystemException exception) {
+ String message = exception.message;
+ String osMessage = exception.osError?.message;
+ if (osMessage != null && osMessage.isNotEmpty) {
+ message = osMessage;
+ }
+ return new FileSystemException(uri, message);
+ }
}
« no previous file with comments | « pkg/front_end/lib/memory_file_system.dart ('k') | pkg/front_end/lib/src/fasta/source/source_loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698