| 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 |
| 11 JSON; | 11 JSON; |
| 12 | 12 |
| 13 import 'dart:io' show | 13 import 'dart:io' show |
| 14 ContentType, | 14 ContentType, |
| 15 HttpClient, | 15 HttpClient, |
| 16 HttpClientRequest, | 16 HttpClientRequest, |
| 17 SocketException, | 17 SocketException, |
| 18 stderr; | 18 stderr; |
| 19 | 19 |
| 20 import 'colors.dart' show | 20 import 'colors.dart' show |
| 21 red; | 21 red; |
| 22 | 22 |
| 23 import 'util/relativize.dart' show |
| 24 relativizeUri; |
| 25 |
| 23 const String defaultServerAddress = "http://127.0.0.1:59410/"; | 26 const String defaultServerAddress = "http://127.0.0.1:59410/"; |
| 24 | 27 |
| 25 /// 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 |
| 26 /// reset between each compilation by calling [resetCrashReporting]. | 29 /// reset between each compilation by calling [resetCrashReporting]. |
| 27 bool hasCrashed = false; | 30 bool hasCrashed = false; |
| 28 | 31 |
| 29 /// 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 |
| 30 /// for [reportCrash]. Should be reset between each compilation by calling | 33 /// for [reportCrash]. Should be reset between each compilation by calling |
| 31 /// [resetCrashReporting]. | 34 /// [resetCrashReporting]. |
| 32 Uri firstSourceUri; | 35 Uri firstSourceUri; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 InputError(this.uri, int charOffset, this.error) | 52 InputError(this.uri, int charOffset, this.error) |
| 50 : this.charOffset = charOffset ?? -1; | 53 : this.charOffset = charOffset ?? -1; |
| 51 | 54 |
| 52 toString() => "InputError: $error"; | 55 toString() => "InputError: $error"; |
| 53 | 56 |
| 54 String format() { | 57 String format() { |
| 55 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 58 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 56 // Windows. | 59 // Windows. |
| 57 String message = red("Error: ${safeToString(error)}"); | 60 String message = red("Error: ${safeToString(error)}"); |
| 58 if (uri != null) { | 61 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 } | |
| 64 String position = charOffset == -1 ? "" : "$charOffset:"; | 62 String position = charOffset == -1 ? "" : "$charOffset:"; |
| 65 return "${uri}:$position $message"; | 63 return "${relativizeUri(uri)}:$position $message"; |
| 66 } else { | 64 } else { |
| 67 return message; | 65 return message; |
| 68 } | 66 } |
| 69 } | 67 } |
| 70 } | 68 } |
| 71 | 69 |
| 72 class Crash { | 70 class Crash { |
| 73 final Uri uri; | 71 final Uri uri; |
| 74 | 72 |
| 75 final int charOffset; | 73 final int charOffset; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return new Future.error(error, trace); | 147 return new Future.error(error, trace); |
| 150 } | 148 } |
| 151 | 149 |
| 152 String safeToString(Object object) { | 150 String safeToString(Object object) { |
| 153 try { | 151 try { |
| 154 return "$object"; | 152 return "$object"; |
| 155 } catch (e) { | 153 } catch (e) { |
| 156 return "Error when converting ${object.runtimeType} to string."; | 154 return "Error when converting ${object.runtimeType} to string."; |
| 157 } | 155 } |
| 158 } | 156 } |
| OLD | NEW |