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

Side by Side Diff: runtime/bin/directory_impl.dart

Issue 10989013: Change IllegalArgumentException to ArgumentError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated co19 test expectations. Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 5
6 class _Directory implements Directory { 6 class _Directory implements Directory {
7 static const CREATE_REQUEST = 0; 7 static const CREATE_REQUEST = 0;
8 static const DELETE_REQUEST = 1; 8 static const DELETE_REQUEST = 1;
9 static const EXISTS_REQUEST = 2; 9 static const EXISTS_REQUEST = 2;
10 static const CREATE_TEMP_REQUEST = 3; 10 static const CREATE_TEMP_REQUEST = 3;
(...skipping 24 matching lines...) Expand all
35 return _directoryService.call(request).transform((response) { 35 return _directoryService.call(request).transform((response) {
36 if (_isErrorResponse(response)) { 36 if (_isErrorResponse(response)) {
37 throw _exceptionFromResponse(response, "Exists failed"); 37 throw _exceptionFromResponse(response, "Exists failed");
38 } 38 }
39 return response == 1; 39 return response == 1;
40 }); 40 });
41 } 41 }
42 42
43 bool existsSync() { 43 bool existsSync() {
44 if (_path is !String) { 44 if (_path is !String) {
45 throw new IllegalArgumentException(); 45 throw new ArgumentError();
46 } 46 }
47 var result = _exists(_path); 47 var result = _exists(_path);
48 if (result is OSError) { 48 if (result is OSError) {
49 throw new DirectoryIOException("Exists failed", _path, result); 49 throw new DirectoryIOException("Exists failed", _path, result);
50 } 50 }
51 return (result == 1); 51 return (result == 1);
52 } 52 }
53 53
54 Future<Directory> create() { 54 Future<Directory> create() {
55 _ensureDirectoryService(); 55 _ensureDirectoryService();
56 List request = new List(2); 56 List request = new List(2);
57 request[0] = CREATE_REQUEST; 57 request[0] = CREATE_REQUEST;
58 request[1] = _path; 58 request[1] = _path;
59 return _directoryService.call(request).transform((response) { 59 return _directoryService.call(request).transform((response) {
60 if (_isErrorResponse(response)) { 60 if (_isErrorResponse(response)) {
61 throw _exceptionFromResponse(response, "Creation failed"); 61 throw _exceptionFromResponse(response, "Creation failed");
62 } 62 }
63 return this; 63 return this;
64 }); 64 });
65 } 65 }
66 66
67 void createSync() { 67 void createSync() {
68 if (_path is !String) { 68 if (_path is !String) {
69 throw new IllegalArgumentException(); 69 throw new ArgumentError();
70 } 70 }
71 var result = _create(_path); 71 var result = _create(_path);
72 if (result is OSError) { 72 if (result is OSError) {
73 throw new DirectoryIOException("Creation failed", _path, result); 73 throw new DirectoryIOException("Creation failed", _path, result);
74 } 74 }
75 } 75 }
76 76
77 Future<Directory> createTemp() { 77 Future<Directory> createTemp() {
78 _ensureDirectoryService(); 78 _ensureDirectoryService();
79 List request = new List(2); 79 List request = new List(2);
80 request[0] = CREATE_TEMP_REQUEST; 80 request[0] = CREATE_TEMP_REQUEST;
81 request[1] = _path; 81 request[1] = _path;
82 return _directoryService.call(request).transform((response) { 82 return _directoryService.call(request).transform((response) {
83 if (_isErrorResponse(response)) { 83 if (_isErrorResponse(response)) {
84 throw _exceptionFromResponse(response, 84 throw _exceptionFromResponse(response,
85 "Creation of temporary directory failed"); 85 "Creation of temporary directory failed");
86 } 86 }
87 return new Directory(response); 87 return new Directory(response);
88 }); 88 });
89 } 89 }
90 90
91 Directory createTempSync() { 91 Directory createTempSync() {
92 if (_path is !String) { 92 if (_path is !String) {
93 throw new IllegalArgumentException(); 93 throw new ArgumentError();
94 } 94 }
95 var result = _createTemp(path); 95 var result = _createTemp(path);
96 if (result is OSError) { 96 if (result is OSError) {
97 throw new DirectoryIOException("Creation of temporary directory failed", 97 throw new DirectoryIOException("Creation of temporary directory failed",
98 _path, 98 _path,
99 result); 99 result);
100 } 100 }
101 return new Directory(result); 101 return new Directory(result);
102 } 102 }
103 103
(...skipping 11 matching lines...) Expand all
115 }); 115 });
116 return completer.future; 116 return completer.future;
117 } 117 }
118 118
119 Future<Directory> delete() { 119 Future<Directory> delete() {
120 return _deleteHelper(false, "Deletion failed"); 120 return _deleteHelper(false, "Deletion failed");
121 } 121 }
122 122
123 void deleteSync() { 123 void deleteSync() {
124 if (_path is !String) { 124 if (_path is !String) {
125 throw new IllegalArgumentException(); 125 throw new ArgumentError();
126 } 126 }
127 var result = _delete(_path, false); 127 var result = _delete(_path, false);
128 if (result is OSError) { 128 if (result is OSError) {
129 throw new DirectoryIOException("Deletion failed", _path, result); 129 throw new DirectoryIOException("Deletion failed", _path, result);
130 } 130 }
131 } 131 }
132 132
133 Future<Directory> deleteRecursively() { 133 Future<Directory> deleteRecursively() {
134 return _deleteHelper(true, "Deletion failed"); 134 return _deleteHelper(true, "Deletion failed");
135 } 135 }
136 136
137 void deleteRecursivelySync() { 137 void deleteRecursivelySync() {
138 if (_path is !String) { 138 if (_path is !String) {
139 throw new IllegalArgumentException(); 139 throw new ArgumentError();
140 } 140 }
141 var result = _delete(_path, true); 141 var result = _delete(_path, true);
142 if (result is OSError) { 142 if (result is OSError) {
143 throw new DirectoryIOException("Deletion failed", _path, result); 143 throw new DirectoryIOException("Deletion failed", _path, result);
144 } 144 }
145 } 145 }
146 146
147 Future<Directory> rename(String newPath) { 147 Future<Directory> rename(String newPath) {
148 _ensureDirectoryService(); 148 _ensureDirectoryService();
149 List request = new List(3); 149 List request = new List(3);
150 request[0] = RENAME_REQUEST; 150 request[0] = RENAME_REQUEST;
151 request[1] = _path; 151 request[1] = _path;
152 request[2] = newPath; 152 request[2] = newPath;
153 return _directoryService.call(request).transform((response) { 153 return _directoryService.call(request).transform((response) {
154 if (_isErrorResponse(response)) { 154 if (_isErrorResponse(response)) {
155 throw _exceptionFromResponse(response, "Rename failed"); 155 throw _exceptionFromResponse(response, "Rename failed");
156 } 156 }
157 return new Directory(newPath); 157 return new Directory(newPath);
158 }); 158 });
159 } 159 }
160 160
161 Directory renameSync(String newPath) { 161 Directory renameSync(String newPath) {
162 if (_path is !String || newPath is !String) { 162 if (_path is !String || newPath is !String) {
163 throw new IllegalArgumentException(); 163 throw new ArgumentError();
164 } 164 }
165 var result = _rename(_path, newPath); 165 var result = _rename(_path, newPath);
166 if (result is OSError) { 166 if (result is OSError) {
167 throw new DirectoryIOException("Rename failed", _path, result); 167 throw new DirectoryIOException("Rename failed", _path, result);
168 } 168 }
169 return new Directory(newPath); 169 return new Directory(newPath);
170 } 170 }
171 171
172 DirectoryLister list([bool recursive = false]) { 172 DirectoryLister list([bool recursive = false]) {
173 return new _DirectoryLister(_path, recursive); 173 return new _DirectoryLister(_path, recursive);
174 } 174 }
175 175
176 String get path { return _path; } 176 String get path { return _path; }
177 177
178 bool _isErrorResponse(response) { 178 bool _isErrorResponse(response) {
179 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE; 179 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE;
180 } 180 }
181 181
182 Exception _exceptionFromResponse(response, String message) { 182 Exception _exceptionFromResponse(response, String message) {
183 assert(_isErrorResponse(response)); 183 assert(_isErrorResponse(response));
184 switch (response[_FileUtils.ERROR_RESPONSE_ERROR_TYPE]) { 184 switch (response[_FileUtils.ERROR_RESPONSE_ERROR_TYPE]) {
185 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE: 185 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE:
186 return new IllegalArgumentException(); 186 return new ArgumentError();
187 case _FileUtils.OSERROR_RESPONSE: 187 case _FileUtils.OSERROR_RESPONSE:
188 var err = new OSError(response[_FileUtils.OSERROR_RESPONSE_MESSAGE], 188 var err = new OSError(response[_FileUtils.OSERROR_RESPONSE_MESSAGE],
189 response[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]); 189 response[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]);
190 return new DirectoryIOException(message, _path, err); 190 return new DirectoryIOException(message, _path, err);
191 default: 191 default:
192 return new Exception("Unknown error"); 192 return new Exception("Unknown error");
193 } 193 }
194 } 194 }
195 195
196 void _ensureDirectoryService() { 196 void _ensureDirectoryService() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 case LIST_DIRECTORY: 233 case LIST_DIRECTORY:
234 if (_onDir != null) _onDir(message[RESPONSE_PATH]); 234 if (_onDir != null) _onDir(message[RESPONSE_PATH]);
235 break; 235 break;
236 case LIST_FILE: 236 case LIST_FILE:
237 if (_onFile != null) _onFile(message[RESPONSE_PATH]); 237 if (_onFile != null) _onFile(message[RESPONSE_PATH]);
238 break; 238 break;
239 case LIST_ERROR: 239 case LIST_ERROR:
240 var errorType = 240 var errorType =
241 message[RESPONSE_ERROR][_FileUtils.ERROR_RESPONSE_ERROR_TYPE]; 241 message[RESPONSE_ERROR][_FileUtils.ERROR_RESPONSE_ERROR_TYPE];
242 if (errorType == _FileUtils.ILLEGAL_ARGUMENT_RESPONSE) { 242 if (errorType == _FileUtils.ILLEGAL_ARGUMENT_RESPONSE) {
243 _reportError(new IllegalArgumentException()); 243 _reportError(new ArgumentError());
244 } else if (errorType == _FileUtils.OSERROR_RESPONSE) { 244 } else if (errorType == _FileUtils.OSERROR_RESPONSE) {
245 var responseError = message[RESPONSE_ERROR]; 245 var responseError = message[RESPONSE_ERROR];
246 var err = new OSError( 246 var err = new OSError(
247 responseError[_FileUtils.OSERROR_RESPONSE_MESSAGE], 247 responseError[_FileUtils.OSERROR_RESPONSE_MESSAGE],
248 responseError[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]); 248 responseError[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]);
249 var errorPath = message[RESPONSE_PATH]; 249 var errorPath = message[RESPONSE_PATH];
250 if (errorPath == null) errorPath = path; 250 if (errorPath == null) errorPath = path;
251 _reportError(new DirectoryIOException("Directory listing failed", 251 _reportError(new DirectoryIOException("Directory listing failed",
252 errorPath, 252 errorPath,
253 err)); 253 err));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } else { 285 } else {
286 throw e; 286 throw e;
287 } 287 }
288 } 288 }
289 289
290 Function _onDir; 290 Function _onDir;
291 Function _onFile; 291 Function _onFile;
292 Function _onDone; 292 Function _onDone;
293 Function _onError; 293 Function _onError;
294 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698