Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 /// Tracks if there has been a crash reported through [reportCrash]. Should be | 28 /// Tracks if there has been a crash reported through [reportCrash]. Should be |
| 29 /// reset between each compilation by calling [resetCrashReporting]. | 29 /// reset between each compilation by calling [resetCrashReporting]. |
| 30 bool hasCrashed = false; | 30 bool hasCrashed = false; |
| 31 | 31 |
| 32 /// Tracks the first source URI that has been read and is used as a fall-back | 32 /// Tracks the first source URI that has been read and is used as a fall-back |
| 33 /// for [reportCrash]. Should be reset between each compilation by calling | 33 /// for [reportCrash]. Should be reset between each compilation by calling |
| 34 /// [resetCrashReporting]. | 34 /// [resetCrashReporting]. |
| 35 Uri firstSourceUri; | 35 Uri firstSourceUri; |
| 36 | 36 |
| 37 /// Used to report an internal error. | |
| 38 /// | |
| 39 /// Internal errors should be avoided as best as possible, but are preferred | |
| 40 /// over assertion failures. Favor error messages that starts with "Internal | |
| 41 /// error: " and a short description that may help a developer debug the issue. | |
| 42 /// This method should be called instead of using `throw`, as this allows us to | |
| 43 /// ensure that there are no throws anywhere in the codebase. | |
| 37 dynamic internalError(Object error) { | 44 dynamic internalError(Object error) { |
| 38 throw error; | 45 throw error; |
| 39 } | 46 } |
| 40 | 47 |
| 48 /// Used to report an error in input. | |
| 49 /// | |
| 50 /// Avoid using this for reporting compile-time errors, instead use | |
| 51 /// `LibraryBuilder.addCompileTimeError` for those. | |
| 52 /// | |
| 53 /// An input error is any error that isn't an internal error. We use the term | |
| 54 /// "input error" in favor of "user error". This way, if an input error isn't | |
| 55 /// handled correctly, the user will never see a stack trace that says "user | |
| 56 /// error". | |
| 41 dynamic inputError(Uri uri, int charOffset, Object error) { | 57 dynamic inputError(Uri uri, int charOffset, Object error) { |
|
Siggi Cherem (dart-lang)
2017/02/10 23:12:32
As error-recovery matures is the idea that if we h
ahe
2017/02/13 14:41:02
There are times when this is the correct method to
| |
| 42 throw new InputError(uri, charOffset, error); | 58 throw new InputError(uri, charOffset, error); |
| 43 } | 59 } |
| 44 | 60 |
| 45 class InputError { | 61 class InputError { |
| 46 final Uri uri; | 62 final Uri uri; |
| 47 | 63 |
| 48 final int charOffset; | 64 final int charOffset; |
| 49 | 65 |
| 50 final Object error; | 66 final Object error; |
| 51 | 67 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 return new Future.error(error, trace); | 163 return new Future.error(error, trace); |
| 148 } | 164 } |
| 149 | 165 |
| 150 String safeToString(Object object) { | 166 String safeToString(Object object) { |
| 151 try { | 167 try { |
| 152 return "$object"; | 168 return "$object"; |
| 153 } catch (e) { | 169 } catch (e) { |
| 154 return "Error when converting ${object.runtimeType} to string."; | 170 return "Error when converting ${object.runtimeType} to string."; |
| 155 } | 171 } |
| 156 } | 172 } |
| OLD | NEW |