| 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 'colors.dart' show red; | 14 import 'colors.dart' show red; |
| 15 | 15 |
| 16 import 'messages.dart' show errorsAreFatal, deprecated_format, isVerbose; | 16 import 'messages.dart' show errorsAreFatal, deprecated_format, isVerbose; |
| 17 | 17 |
| 18 const String defaultServerAddress = "http://127.0.0.1:59410/"; | 18 const String defaultServerAddress = "http://127.0.0.1:59410/"; |
| 19 | 19 |
| 20 /// Tracks if there has been a crash reported through [reportCrash]. Should be | 20 /// Tracks if there has been a crash reported through [reportCrash]. Should be |
| 21 /// reset between each compilation by calling [resetCrashReporting]. | 21 /// reset between each compilation by calling [resetCrashReporting]. |
| 22 bool hasCrashed = false; | 22 bool hasCrashed = false; |
| 23 | 23 |
| 24 /// Tracks the first source URI that has been read and is used as a fall-back | 24 /// Tracks the first source URI that has been read and is used as a fall-back |
| 25 /// for [reportCrash]. Should be reset between each compilation by calling | 25 /// for [reportCrash]. Should be reset between each compilation by calling |
| 26 /// [resetCrashReporting]. | 26 /// [resetCrashReporting]. |
| 27 Uri firstSourceUri; | 27 Uri firstSourceUri; |
| 28 | 28 |
| 29 /// This flag is a temporary solution for preventing printing a lot |
| 30 /// of information on the console. Analyzer starts using Fasta to generate |
| 31 /// kernels to resynthesize its element models from it. We don't want to |
| 32 /// see all these errors and warnings on the console, while running test or |
| 33 /// in production. TODO(scheglov): remove this flag eventually. |
| 34 bool temporaryUntilPrintsRemovedEnablePrinting = true; |
| 35 |
| 29 /// Used to report an error in input. | 36 /// Used to report an error in input. |
| 30 /// | 37 /// |
| 31 /// Avoid using this for reporting compile-time errors, instead use | 38 /// Avoid using this for reporting compile-time errors, instead use |
| 32 /// `LibraryBuilder.addCompileTimeError` for those. | 39 /// `LibraryBuilder.addCompileTimeError` for those. |
| 33 /// | 40 /// |
| 34 /// An input error is any error that isn't an internal error. We use the term | 41 /// An input error is any error that isn't an internal error. We use the term |
| 35 /// "input error" in favor of "user error". This way, if an input error isn't | 42 /// "input error" in favor of "user error". This way, if an input error isn't |
| 36 /// handled correctly, the user will never see a stack trace that says "user | 43 /// handled correctly, the user will never see a stack trace that says "user |
| 37 /// error". | 44 /// error". |
| 38 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { | 45 dynamic deprecated_inputError(Uri uri, int charOffset, Object error) { |
| 39 if (errorsAreFatal && isVerbose) { | 46 if (errorsAreFatal && isVerbose) { |
| 40 print(StackTrace.current); | 47 print(StackTrace.current); |
| 41 } | 48 } |
| 42 throw new deprecated_InputError(uri, charOffset, error); | 49 throw new deprecated_InputError(uri, charOffset, error); |
| 43 } | 50 } |
| 44 | 51 |
| 45 String deprecated_printUnexpected(Uri uri, int charOffset, String message) { | 52 String deprecated_printUnexpected(Uri uri, int charOffset, String message) { |
| 46 String formattedMessage = | 53 String formattedMessage = |
| 47 deprecated_formatUnexpected(uri, charOffset, message); | 54 deprecated_formatUnexpected(uri, charOffset, message); |
| 48 if (errorsAreFatal) { | 55 if (errorsAreFatal) { |
| 49 print(formattedMessage); | 56 print(formattedMessage); |
| 50 if (isVerbose) print(StackTrace.current); | 57 if (isVerbose) print(StackTrace.current); |
| 51 throw new deprecated_InputError(uri, charOffset, message); | 58 throw new deprecated_InputError(uri, charOffset, message); |
| 52 } | 59 } |
| 53 print(formattedMessage); | 60 if (temporaryUntilPrintsRemovedEnablePrinting) { |
| 61 print(formattedMessage); |
| 62 } |
| 54 return formattedMessage; | 63 return formattedMessage; |
| 55 } | 64 } |
| 56 | 65 |
| 57 String deprecated_formatUnexpected(Uri uri, int charOffset, String message) { | 66 String deprecated_formatUnexpected(Uri uri, int charOffset, String message) { |
| 58 return deprecated_format(uri, charOffset, colorError("Error: $message")); | 67 return deprecated_format(uri, charOffset, colorError("Error: $message")); |
| 59 } | 68 } |
| 60 | 69 |
| 61 String colorError(String message) { | 70 String colorError(String message) { |
| 62 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 71 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 63 // Windows. | 72 // Windows. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return new Future.error(error, trace); | 170 return new Future.error(error, trace); |
| 162 } | 171 } |
| 163 | 172 |
| 164 String safeToString(Object object) { | 173 String safeToString(Object object) { |
| 165 try { | 174 try { |
| 166 return "$object"; | 175 return "$object"; |
| 167 } catch (e) { | 176 } catch (e) { |
| 168 return "Error when converting ${object.runtimeType} to string."; | 177 return "Error when converting ${object.runtimeType} to string."; |
| 169 } | 178 } |
| 170 } | 179 } |
| OLD | NEW |