| 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 Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
| 10 | 10 |
| 11 import 'dart:io' | 11 import 'dart:io' |
| 12 show ContentType, HttpClient, HttpClientRequest, SocketException, stderr; | 12 show ContentType, HttpClient, HttpClientRequest, SocketException, stderr; |
| 13 | 13 |
| 14 import 'command_line_reporting.dart' show isFatal; | 14 import 'command_line_reporting.dart' show shouldThrowOn; |
| 15 | 15 |
| 16 import 'messages.dart' show LocatedMessage, isVerbose, templateUnspecified; | 16 import 'messages.dart' show LocatedMessage, isVerbose, templateUnspecified; |
| 17 | 17 |
| 18 import 'severity.dart' show Severity; | 18 import 'severity.dart' show Severity; |
| 19 | 19 |
| 20 const String defaultServerAddress = "http://127.0.0.1:59410/"; | 20 const String defaultServerAddress = "http://127.0.0.1:59410/"; |
| 21 | 21 |
| 22 /// Tracks if there has been a crash reported through [reportCrash]. Should be | 22 /// Tracks if there has been a crash reported through [reportCrash]. Should be |
| 23 /// reset between each compilation by calling [resetCrashReporting]. | 23 /// reset between each compilation by calling [resetCrashReporting]. |
| 24 bool hasCrashed = false; | 24 bool hasCrashed = false; |
| 25 | 25 |
| 26 /// Tracks the first source URI that has been read and is used as a fall-back | 26 /// Tracks the first source URI that has been read and is used as a fall-back |
| 27 /// for [reportCrash]. Should be reset between each compilation by calling | 27 /// for [reportCrash]. Should be reset between each compilation by calling |
| 28 /// [resetCrashReporting]. | 28 /// [resetCrashReporting]. |
| 29 Uri firstSourceUri; | 29 Uri firstSourceUri; |
| 30 | 30 |
| 31 /// Used to report an error in input. | 31 /// Used to report an error in input. |
| 32 /// | 32 /// |
| 33 /// Avoid using this for reporting compile-time errors, instead use | 33 /// Avoid using this for reporting compile-time errors, instead use |
| 34 /// `LibraryBuilder.addCompileTimeError` for those. | 34 /// `LibraryBuilder.addCompileTimeError` for those. |
| 35 /// | 35 /// |
| 36 /// An input error is any error that isn't an internal error. We use the term | 36 /// An input error is any error that isn't an internal error. We use the term |
| 37 /// "input error" in favor of "user error". This way, if an input error isn't | 37 /// "input error" in favor of "user error". This way, if an input error isn't |
| 38 /// handled correctly, the user will never see a stack trace that says "user | 38 /// handled correctly, the user will never see a stack trace that says "user |
| 39 /// error". | 39 /// error". |
| 40 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { | 40 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { |
| 41 if (isFatal(Severity.error) && isVerbose) { | 41 if (shouldThrowOn(Severity.error) && isVerbose) { |
| 42 print(StackTrace.current); | 42 print(StackTrace.current); |
| 43 } | 43 } |
| 44 throw new deprecated_InputError(uri, charOffset, error); | 44 throw new deprecated_InputError(uri, charOffset, error); |
| 45 } | 45 } |
| 46 | 46 |
| 47 class deprecated_InputError { | 47 class deprecated_InputError { |
| 48 final Uri uri; | 48 final Uri uri; |
| 49 | 49 |
| 50 final int charOffset; | 50 final int charOffset; |
| 51 | 51 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return new Future.error(error, trace); | 149 return new Future.error(error, trace); |
| 150 } | 150 } |
| 151 | 151 |
| 152 String safeToString(Object object) { | 152 String safeToString(Object object) { |
| 153 try { | 153 try { |
| 154 return "$object"; | 154 return "$object"; |
| 155 } catch (e) { | 155 } catch (e) { |
| 156 return "Error when converting ${object.runtimeType} to string."; | 156 return "Error when converting ${object.runtimeType} to string."; |
| 157 } | 157 } |
| 158 } | 158 } |
| OLD | NEW |