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