| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 InputError(this.uri, int charOffset, this.error) | 49 InputError(this.uri, int charOffset, this.error) |
| 50 : this.charOffset = charOffset ?? -1; | 50 : this.charOffset = charOffset ?? -1; |
| 51 | 51 |
| 52 toString() => "InputError: $error"; | 52 toString() => "InputError: $error"; |
| 53 | 53 |
| 54 String format() { | 54 String format() { |
| 55 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 55 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 56 // Windows. | 56 // Windows. |
| 57 String message = red("Error: ${safeToString(error)}"); | 57 String message = red("Error: ${safeToString(error)}"); |
| 58 if (uri != null) { | 58 if (uri != null) { |
| 59 String uri = "${this.uri}"; |
| 60 String base = "${Uri.base}"; |
| 61 if (uri.startsWith(base)) { |
| 62 uri = uri.substring(base.length); |
| 63 } |
| 59 String position = charOffset == -1 ? "" : "$charOffset:"; | 64 String position = charOffset == -1 ? "" : "$charOffset:"; |
| 60 return "${uri}:$position $message"; | 65 return "${uri}:$position $message"; |
| 61 } else { | 66 } else { |
| 62 return message; | 67 return message; |
| 63 } | 68 } |
| 64 } | 69 } |
| 65 } | 70 } |
| 66 | 71 |
| 67 class Crash { | 72 class Crash { |
| 68 final Uri uri; | 73 final Uri uri; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return new Future.error(error, trace); | 149 return new Future.error(error, trace); |
| 145 } | 150 } |
| 146 | 151 |
| 147 String safeToString(Object object) { | 152 String safeToString(Object object) { |
| 148 try { | 153 try { |
| 149 return "$object"; | 154 return "$object"; |
| 150 } catch (e) { | 155 } catch (e) { |
| 151 return "Error when converting ${object.runtimeType} to string."; | 156 return "Error when converting ${object.runtimeType} to string."; |
| 152 } | 157 } |
| 153 } | 158 } |
| OLD | NEW |