| 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 | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 /// | 58 /// |
| 59 /// An input error is any error that isn't an internal error. We use the term | 59 /// An input error is any error that isn't an internal error. We use the term |
| 60 /// "input error" in favor of "user error". This way, if an input error isn't | 60 /// "input error" in favor of "user error". This way, if an input error isn't |
| 61 /// handled correctly, the user will never see a stack trace that says "user | 61 /// handled correctly, the user will never see a stack trace that says "user |
| 62 /// error". | 62 /// error". |
| 63 dynamic inputError(Uri uri, int charOffset, Object error) { | 63 dynamic inputError(Uri uri, int charOffset, Object error) { |
| 64 throw new InputError(uri, charOffset, error); | 64 throw new InputError(uri, charOffset, error); |
| 65 } | 65 } |
| 66 | 66 |
| 67 String printUnexpected(Uri uri, int charOffset, String message) { | 67 String printUnexpected(Uri uri, int charOffset, String message) { |
| 68 String formattedMessage = formatUnexpected(uri, charOffset, message); |
| 68 if (errorsAreFatal) { | 69 if (errorsAreFatal) { |
| 70 print(formattedMessage); |
| 69 if (isVerbose) print(StackTrace.current); | 71 if (isVerbose) print(StackTrace.current); |
| 70 throw new InputError(uri, charOffset, message); | 72 throw new InputError(uri, charOffset, message); |
| 71 } | 73 } |
| 72 message = formatUnexpected(uri, charOffset, message); | 74 print(formattedMessage); |
| 73 print(message); | 75 return formattedMessage; |
| 74 return message; | |
| 75 } | 76 } |
| 76 | 77 |
| 77 String formatUnexpected(Uri uri, int charOffset, String message) { | 78 String formatUnexpected(Uri uri, int charOffset, String message) { |
| 78 return format(uri, charOffset, colorError("Error: $message")); | 79 return format(uri, charOffset, colorError("Error: $message")); |
| 79 } | 80 } |
| 80 | 81 |
| 81 String colorError(String message) { | 82 String colorError(String message) { |
| 82 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 83 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 83 // Windows. | 84 // Windows. |
| 84 return red(message); | 85 return red(message); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return new Future.error(error, trace); | 180 return new Future.error(error, trace); |
| 180 } | 181 } |
| 181 | 182 |
| 182 String safeToString(Object object) { | 183 String safeToString(Object object) { |
| 183 try { | 184 try { |
| 184 return "$object"; | 185 return "$object"; |
| 185 } catch (e) { | 186 } catch (e) { |
| 186 return "Error when converting ${object.runtimeType} to string."; | 187 return "Error when converting ${object.runtimeType} to string."; |
| 187 } | 188 } |
| 188 } | 189 } |
| OLD | NEW |