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, 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. | 29 /// Used to report an internal error. |
30 /// | 30 /// |
31 /// Internal errors should be avoided as best as possible, but are preferred | 31 /// Internal errors should be avoided as best as possible, but are preferred |
32 /// over assertion failures. Favor error messages that starts with "Internal | 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. | 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 | 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. | 35 /// ensure that there are no throws anywhere in the codebase. |
36 dynamic internalError(Object error, [Uri uri, int charOffset = -1]) { | 36 dynamic deprecated_internalProblem(Object error, |
Siggi Cherem (dart-lang)
2017/07/07 15:28:04
I'm not sure we get that much value from doing a r
| |
37 [Uri uri, int charOffset = -1]) { | |
37 if (uri == null && charOffset == -1) { | 38 if (uri == null && charOffset == -1) { |
38 throw error; | 39 throw error; |
39 } else { | 40 } else { |
40 throw format(uri, charOffset, "Internal error: ${safeToString(error)}"); | 41 throw deprecated_format( |
42 uri, charOffset, "Internal error: ${safeToString(error)}"); | |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 /// Used to report an error in input. | 46 /// Used to report an error in input. |
45 /// | 47 /// |
46 /// Avoid using this for reporting compile-time errors, instead use | 48 /// Avoid using this for reporting compile-time errors, instead use |
47 /// `LibraryBuilder.addCompileTimeError` for those. | 49 /// `LibraryBuilder.deprecated_addCompileTimeError` for those. |
48 /// | 50 /// |
49 /// An input error is any error that isn't an internal error. We use the term | 51 /// An input error is any error that isn't an internal error. We use the term |
50 /// "input error" in favor of "user error". This way, if an input error isn't | 52 /// "input error" in favor of "user error". This way, if an input error isn't |
51 /// handled correctly, the user will never see a stack trace that says "user | 53 /// handled correctly, the user will never see a stack trace that says "user |
52 /// error". | 54 /// error". |
53 dynamic inputError(Uri uri, int charOffset, Object error) { | 55 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { |
54 if (errorsAreFatal && isVerbose) { | 56 if (errorsAreFatal && isVerbose) { |
55 print(StackTrace.current); | 57 print(StackTrace.current); |
56 } | 58 } |
57 throw new InputError(uri, charOffset, error); | 59 throw new deprecated_InputError(uri, charOffset, error); |
58 } | 60 } |
59 | 61 |
60 String printUnexpected(Uri uri, int charOffset, String message) { | 62 String deprecated_printUnexpected(Uri uri, int charOffset, String message) { |
61 String formattedMessage = formatUnexpected(uri, charOffset, message); | 63 String formattedMessage = |
64 deprecated_formatUnexpected(uri, charOffset, message); | |
62 if (errorsAreFatal) { | 65 if (errorsAreFatal) { |
63 print(formattedMessage); | 66 print(formattedMessage); |
64 if (isVerbose) print(StackTrace.current); | 67 if (isVerbose) print(StackTrace.current); |
65 throw new InputError(uri, charOffset, message); | 68 throw new deprecated_InputError(uri, charOffset, message); |
66 } | 69 } |
67 print(formattedMessage); | 70 print(formattedMessage); |
68 return formattedMessage; | 71 return formattedMessage; |
69 } | 72 } |
70 | 73 |
71 String formatUnexpected(Uri uri, int charOffset, String message) { | 74 String deprecated_formatUnexpected(Uri uri, int charOffset, String message) { |
72 return format(uri, charOffset, colorError("Error: $message")); | 75 return deprecated_format(uri, charOffset, colorError("Error: $message")); |
73 } | 76 } |
74 | 77 |
75 String colorError(String message) { | 78 String colorError(String message) { |
76 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 79 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
77 // Windows. | 80 // Windows. |
78 return red(message); | 81 return red(message); |
79 } | 82 } |
80 | 83 |
81 class InputError { | 84 class deprecated_InputError { |
82 final Uri uri; | 85 final Uri uri; |
83 | 86 |
84 final int charOffset; | 87 final int charOffset; |
85 | 88 |
86 final Object error; | 89 final Object error; |
87 | 90 |
88 InputError(this.uri, int charOffset, this.error) | 91 deprecated_InputError(this.uri, int charOffset, this.error) |
89 : this.charOffset = charOffset ?? -1; | 92 : this.charOffset = charOffset ?? -1; |
90 | 93 |
91 toString() => "InputError: $error"; | 94 toString() => "deprecated_InputError: $error"; |
92 | 95 |
93 String format() => formatUnexpected(uri, charOffset, safeToString(error)); | 96 String deprecated_format() => |
97 deprecated_formatUnexpected(uri, charOffset, safeToString(error)); | |
94 } | 98 } |
95 | 99 |
96 class Crash { | 100 class Crash { |
97 final Uri uri; | 101 final Uri uri; |
98 | 102 |
99 final int charOffset; | 103 final int charOffset; |
100 | 104 |
101 final Object error; | 105 final Object error; |
102 | 106 |
103 final StackTrace trace; | 107 final StackTrace trace; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return new Future.error(error, trace); | 178 return new Future.error(error, trace); |
175 } | 179 } |
176 | 180 |
177 String safeToString(Object object) { | 181 String safeToString(Object object) { |
178 try { | 182 try { |
179 return "$object"; | 183 return "$object"; |
180 } catch (e) { | 184 } catch (e) { |
181 return "Error when converting ${object.runtimeType} to string."; | 185 return "Error when converting ${object.runtimeType} to string."; |
182 } | 186 } |
183 } | 187 } |
OLD | NEW |