OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library unittest.load_exception; | |
6 | |
7 import 'dart:isolate'; | |
8 | |
9 import 'package:path/path.dart' as p; | |
10 | |
11 import 'utils.dart'; | |
12 | |
13 class LoadException implements Exception { | |
14 final String path; | |
15 | |
16 final innerError; | |
17 | |
18 LoadException(this.path, this.innerError); | |
19 | |
20 String toString() { | |
21 var buffer = new StringBuffer('Failed to load "$path":'); | |
22 | |
23 var innerString = getErrorMessage(innerError); | |
24 if (innerError is IsolateSpawnException) { | |
25 // If this is a parse error, get rid of the noisy preamble. | |
26 innerString = innerString | |
27 .replaceFirst("'${p.toUri(p.absolute(path))}': error: ", ""); | |
28 | |
29 // If this is a file system error, get rid of both the preamble and the | |
30 // useless stack trace. | |
31 innerString = innerString.replaceFirst( | |
32 "Unhandled exception:\n" | |
33 "Uncaught Error: Load Error: FileSystemException: ", | |
34 ""); | |
35 innerString = innerString.split("Stack Trace:\n").first.trim(); | |
36 } | |
37 | |
38 buffer.write(innerString.contains("\n") ? "\n" : " "); | |
39 buffer.write(innerString); | |
40 return buffer.toString(); | |
41 } | |
42 } | |
OLD | NEW |