OLD | NEW |
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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
6 library utils; | 6 library utils; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:crypto'; | 9 import 'dart:crypto'; |
| 10 import 'dart:io'; |
10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
11 import 'dart:uri'; | 12 import 'dart:uri'; |
12 | 13 |
13 /// A pair of values. | 14 /// A pair of values. |
14 class Pair<E, F> { | 15 class Pair<E, F> { |
15 E first; | 16 E first; |
16 F last; | 17 F last; |
17 | 18 |
18 Pair(this.first, this.last); | 19 Pair(this.first, this.last); |
19 | 20 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 .then((resolved) => new Pair(key, resolved))); | 352 .then((resolved) => new Pair(key, resolved))); |
352 }); | 353 }); |
353 return Future.wait(pairs).then((resolvedPairs) { | 354 return Future.wait(pairs).then((resolvedPairs) { |
354 var map = {}; | 355 var map = {}; |
355 for (var pair in resolvedPairs) { | 356 for (var pair in resolvedPairs) { |
356 map[pair.first] = pair.last; | 357 map[pair.first] = pair.last; |
357 } | 358 } |
358 return map; | 359 return map; |
359 }); | 360 }); |
360 } | 361 } |
| 362 |
| 363 /// An exception class for exceptions that are intended to be seen by the user. |
| 364 /// These exceptions won't have any debugging information printed when they're |
| 365 /// thrown. |
| 366 class UserFacingException implements Exception { |
| 367 final String message; |
| 368 |
| 369 UserFacingException(this.message); |
| 370 } |
| 371 |
| 372 /// Returns whether [error] is a user-facing error object. This includes both |
| 373 /// [UserFacingException] and any dart:io errors. |
| 374 bool isUserFacingException(error) { |
| 375 return error is UserFacingException || |
| 376 // TODO(nweiz): clean up this branch when issue 9955 is fixed. |
| 377 error is DirectoryIOException || |
| 378 error is FileIOException || |
| 379 error is HttpException || |
| 380 error is HttpParserException || |
| 381 error is LinkIOException || |
| 382 error is MimeParserException || |
| 383 error is OSError || |
| 384 error is ProcessException || |
| 385 error is SocketIOException || |
| 386 error is WebSocketException; |
| 387 } |
OLD | NEW |