OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.errors; | 5 library fasta.errors; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
10 | 10 |
11 import 'dart:io' | 11 import 'dart:io' |
12 show ContentType, HttpClient, HttpClientRequest, SocketException, stderr; | 12 show ContentType, HttpClient, HttpClientRequest, SocketException, stderr; |
13 | 13 |
14 import 'colors.dart' show red; | 14 import 'colors.dart' show red; |
15 | 15 |
16 import 'messages.dart' show errorsAreFatal, deprecated_format, isVerbose; | 16 import 'messages.dart' show errorsAreFatal, deprecated_format, isVerbose; |
17 | 17 |
18 const String defaultServerAddress = "http://127.0.0.1:59410/"; | 18 const String defaultServerAddress = "http://127.0.0.1:59410/"; |
19 | 19 |
20 /// Tracks if there has been a crash reported through [reportCrash]. Should be | 20 /// Tracks if there has been a crash reported through [reportCrash]. Should be |
21 /// reset between each compilation by calling [resetCrashReporting]. | 21 /// reset between each compilation by calling [resetCrashReporting]. |
22 bool hasCrashed = false; | 22 bool hasCrashed = false; |
23 | 23 |
24 /// Tracks the first source URI that has been read and is used as a fall-back | 24 /// Tracks the first source URI that has been read and is used as a fall-back |
25 /// for [reportCrash]. Should be reset between each compilation by calling | 25 /// for [reportCrash]. Should be reset between each compilation by calling |
26 /// [resetCrashReporting]. | 26 /// [resetCrashReporting]. |
27 Uri firstSourceUri; | 27 Uri firstSourceUri; |
28 | 28 |
29 /// Used to report an internal error. | |
30 /// | |
31 /// Internal errors should be avoided as best as possible, but are preferred | |
32 /// over assertion failures. Favor error messages that starts with "Internal | |
33 /// error: " and a short description that may help a developer debug the issue. | |
34 /// This method should be called instead of using `throw`, as this allows us to | |
35 /// ensure that there are no throws anywhere in the codebase. | |
36 dynamic deprecated_internalProblem(Object error, | |
37 [Uri uri, int charOffset = -1]) { | |
38 if (uri == null && charOffset == -1) { | |
39 throw error; | |
40 } else { | |
41 throw deprecated_format( | |
42 uri, charOffset, "Internal error: ${safeToString(error)}"); | |
43 } | |
44 } | |
45 | |
46 /// Used to report an error in input. | 29 /// Used to report an error in input. |
47 /// | 30 /// |
48 /// Avoid using this for reporting compile-time errors, instead use | 31 /// Avoid using this for reporting compile-time errors, instead use |
49 /// `LibraryBuilder.deprecated_addCompileTimeError` for those. | 32 /// `LibraryBuilder.deprecated_addCompileTimeError` for those. |
50 /// | 33 /// |
51 /// An input error is any error that isn't an internal error. We use the term | 34 /// An input error is any error that isn't an internal error. We use the term |
52 /// "input error" in favor of "user error". This way, if an input error isn't | 35 /// "input error" in favor of "user error". This way, if an input error isn't |
53 /// handled correctly, the user will never see a stack trace that says "user | 36 /// handled correctly, the user will never see a stack trace that says "user |
54 /// error". | 37 /// error". |
55 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { | 38 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return new Future.error(error, trace); | 161 return new Future.error(error, trace); |
179 } | 162 } |
180 | 163 |
181 String safeToString(Object object) { | 164 String safeToString(Object object) { |
182 try { | 165 try { |
183 return "$object"; | 166 return "$object"; |
184 } catch (e) { | 167 } catch (e) { |
185 return "Error when converting ${object.runtimeType} to string."; | 168 return "Error when converting ${object.runtimeType} to string."; |
186 } | 169 } |
187 } | 170 } |
OLD | NEW |