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

Unified Diff: runtime/bin/file_impl.dart

Issue 9630012: Error reporting on File in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made Dart OSError constructor const Created 8 years, 9 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
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 8ab5bbbf29afdd5e61c5212dd2c4bdf2f46cc393..2fcf36e4829a5f91a95a291a135f030e951ad7ad 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -251,7 +251,7 @@ class _FileUtils {
}
static bool exists(String name) native "File_Exists";
- static int open(String name, int mode) native "File_Open";
+ static open(String name, int mode) native "File_Open";
Mads Ager (google) 2012/03/09 09:40:13 Do we want 'void' here?
Søren Gjesse 2012/03/13 08:25:55 No, open now returns either an int or an instance
static bool create(String name) native "File_Create";
static bool delete(String name) native "File_Delete";
static String fullPath(String name) native "File_FullPath";
@@ -280,8 +280,14 @@ class _FileUtils {
static SendPort newServicePort() native "File_NewServicePort";
static int checkedOpen(String name, int mode) {
- if (name is !String || mode is !int) return 0;
- return open(name, mode);
+ if (name is !String || mode is !int) {
+ throw new IllegalArgumentException();
+ };
+ var result = open(name, mode);
+ if (result is OSError) {
+ throw new FileIOException("Cannot open file", result);
+ }
+ return result;
}
static bool checkedCreate(String name) {
@@ -440,11 +446,14 @@ class _File implements File {
request[0] = _FileUtils.kOpenRequest;
request[1] = _name;
request[2] = mode._mode; // Direct int value for serialization.
- _fileService.call(request).receive((id, replyTo) {
- if (id != 0) {
+ _fileService.call(request).receive((result, replyTo) {
+ if (result is Array) {
+ if (_onError != null) {
+ _onError(new FileIOException(
+ "Cannot open file", new OSError(result[1], result[0])));
+ }
+ } else {
callback(new _RandomAccessFile(id, _name));
- } else if (_onError != null) {
- _onError("Cannot open file: $_name");
}
});
}
@@ -461,9 +470,7 @@ class _File implements File {
"FileMode.WRITE or FileMode.APPEND.");
}
var id = _FileUtils.checkedOpen(_name, mode._mode);
- if (id == 0) {
- throw new FileIOException("Cannot open file: $_name");
- }
+ assert(id != 0);
return new _RandomAccessFile(id, _name);
}

Powered by Google App Engine
This is Rietveld 408576698