| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.problems; | 5 library fasta.problems; |
| 6 | 6 |
| 7 import 'messages.dart' | 7 import 'messages.dart' |
| 8 show | 8 show |
| 9 Message, | 9 Message, |
| 10 deprecated_format, | 10 deprecated_format, |
| 11 templateUnexpected, | 11 templateUnexpected, |
| 12 templateUnhandled, | 12 templateUnhandled, |
| 13 templateUnimplemented, | 13 templateUnimplemented, |
| 14 templateUnsupported; | 14 templateUnsupported; |
| 15 | 15 |
| 16 /// Used to report an internal error. | 16 /// Used to report an internal error. |
| 17 /// | 17 /// |
| 18 /// Internal errors should be avoided as best as possible, but are preferred | 18 /// Internal errors should be avoided as best as possible, but are preferred |
| 19 /// over assertion failures. The message should contain a short description | 19 /// over assertion failures. The message should start with "Internal error:" |
| 20 /// that may help a developer debug the issue. This method should be called | 20 /// and contain a short description that may help a developer debug the issue. |
| 21 /// instead of using `throw`, as this allows us to ensure that there are no | 21 /// This method should be called instead of using `throw`, as this allows us to |
| 22 /// throws anywhere else in the codebase. | 22 /// ensure that there are no throws anywhere else in the codebase. |
| 23 dynamic internalProblem(Message message, int charOffset, Uri uri) { | 23 dynamic internalProblem(Message message, int charOffset, Uri uri) { |
| 24 String text = "Internal problem: ${message.message}"; | |
| 25 if (uri == null && charOffset == -1) { | 24 if (uri == null && charOffset == -1) { |
| 26 throw text; | 25 throw message.message; |
| 27 } else { | 26 } else { |
| 28 throw deprecated_format(uri, charOffset, text); | 27 throw deprecated_format(uri, charOffset, message.message); |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 dynamic unimplemented(String what, int charOffset, Uri uri) { | 31 dynamic unimplemented(String what, int charOffset, Uri uri) { |
| 33 return internalProblem( | 32 return internalProblem( |
| 34 templateUnimplemented.withArguments(what), charOffset, uri); | 33 templateUnimplemented.withArguments(what), charOffset, uri); |
| 35 } | 34 } |
| 36 | 35 |
| 37 dynamic unhandled(String what, String where, int charOffset, Uri uri) { | 36 dynamic unhandled(String what, String where, int charOffset, Uri uri) { |
| 38 return internalProblem( | 37 return internalProblem( |
| 39 templateUnhandled.withArguments(what, where), charOffset, uri); | 38 templateUnhandled.withArguments(what, where), charOffset, uri); |
| 40 } | 39 } |
| 41 | 40 |
| 42 dynamic unexpected(String expected, String actual, int charOffset, Uri uri) { | 41 dynamic unexpected(String expected, String actual, int charOffset, Uri uri) { |
| 43 return internalProblem( | 42 return internalProblem( |
| 44 templateUnexpected.withArguments(expected, actual), charOffset, uri); | 43 templateUnexpected.withArguments(expected, actual), charOffset, uri); |
| 45 } | 44 } |
| 46 | 45 |
| 47 dynamic unsupported(String operation, int charOffset, Uri uri) { | 46 dynamic unsupported(String operation, int charOffset, Uri uri) { |
| 48 return internalProblem( | 47 return internalProblem( |
| 49 templateUnsupported.withArguments(operation), charOffset, uri); | 48 templateUnsupported.withArguments(operation), charOffset, uri); |
| 50 } | 49 } |
| OLD | NEW |