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 Future; |
8 Future; | |
9 | 8 |
10 import 'dart:convert' show | 9 import 'dart:convert' show JSON; |
11 JSON; | |
12 | 10 |
13 import 'dart:io' show | 11 import 'dart:io' |
14 ContentType, | 12 show ContentType, HttpClient, HttpClientRequest, SocketException, stderr; |
15 HttpClient, | |
16 HttpClientRequest, | |
17 SocketException, | |
18 stderr; | |
19 | 13 |
20 import 'colors.dart' show | 14 import 'colors.dart' show red; |
21 red; | |
22 | 15 |
23 import 'messages.dart' show | 16 import 'messages.dart' show errorsAreFatal, format, isVerbose; |
24 errorsAreFatal, | |
25 format, | |
26 isVerbose; | |
27 | 17 |
28 const String defaultServerAddress = "http://127.0.0.1:59410/"; | 18 const String defaultServerAddress = "http://127.0.0.1:59410/"; |
29 | 19 |
30 /// 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 |
31 /// reset between each compilation by calling [resetCrashReporting]. | 21 /// reset between each compilation by calling [resetCrashReporting]. |
32 bool hasCrashed = false; | 22 bool hasCrashed = false; |
33 | 23 |
34 /// 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 |
35 /// for [reportCrash]. Should be reset between each compilation by calling | 25 /// for [reportCrash]. Should be reset between each compilation by calling |
36 /// [resetCrashReporting]. | 26 /// [resetCrashReporting]. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void resetCrashReporting() { | 113 void resetCrashReporting() { |
124 firstSourceUri = null; | 114 firstSourceUri = null; |
125 hasCrashed = false; | 115 hasCrashed = false; |
126 } | 116 } |
127 | 117 |
128 Future reportCrash(error, StackTrace trace, [Uri uri, int charOffset]) async { | 118 Future reportCrash(error, StackTrace trace, [Uri uri, int charOffset]) async { |
129 note(String note) async { | 119 note(String note) async { |
130 stderr.write(note); | 120 stderr.write(note); |
131 await stderr.flush(); | 121 await stderr.flush(); |
132 } | 122 } |
| 123 |
133 if (hasCrashed) return new Future.error(error, trace); | 124 if (hasCrashed) return new Future.error(error, trace); |
134 if (error is Crash) { | 125 if (error is Crash) { |
135 trace = error.trace ?? trace; | 126 trace = error.trace ?? trace; |
136 uri = error.uri ?? uri; | 127 uri = error.uri ?? uri; |
137 charOffset = error.charOffset ?? charOffset; | 128 charOffset = error.charOffset ?? charOffset; |
138 error = error.error; | 129 error = error.error; |
139 } | 130 } |
140 uri ??= firstSourceUri; | 131 uri ??= firstSourceUri; |
141 hasCrashed = true; | 132 hasCrashed = true; |
142 Map<String, dynamic> data = <String, dynamic>{}; | 133 Map<String, dynamic> data = <String, dynamic>{}; |
(...skipping 16 matching lines...) Expand all Loading... |
159 return new Future.error(error, trace); | 150 return new Future.error(error, trace); |
160 } | 151 } |
161 if (request != null) { | 152 if (request != null) { |
162 await note("\nSending crash report data"); | 153 await note("\nSending crash report data"); |
163 request.persistentConnection = false; | 154 request.persistentConnection = false; |
164 request.bufferOutput = false; | 155 request.bufferOutput = false; |
165 String host = request?.connectionInfo?.remoteAddress?.host; | 156 String host = request?.connectionInfo?.remoteAddress?.host; |
166 int port = request?.connectionInfo?.remotePort; | 157 int port = request?.connectionInfo?.remotePort; |
167 await note(" to $host:$port"); | 158 await note(" to $host:$port"); |
168 await request | 159 await request |
169 ..headers.contentType = ContentType.JSON | 160 ..headers.contentType = ContentType.JSON |
170 ..write(json); | 161 ..write(json); |
171 await request.close(); | 162 await request.close(); |
172 await note("."); | 163 await note("."); |
173 } | 164 } |
174 } catch (e, s) { | 165 } catch (e, s) { |
175 await note("\n${safeToString(e)}\n$s\n"); | 166 await note("\n${safeToString(e)}\n$s\n"); |
176 await note("\n\n\nFE::ERROR::$json\n\n\n"); | 167 await note("\n\n\nFE::ERROR::$json\n\n\n"); |
177 } | 168 } |
178 await client.close(force: true); | 169 await client.close(force: true); |
179 await note("\n"); | 170 await note("\n"); |
180 return new Future.error(error, trace); | 171 return new Future.error(error, trace); |
181 } | 172 } |
182 | 173 |
183 String safeToString(Object object) { | 174 String safeToString(Object object) { |
184 try { | 175 try { |
185 return "$object"; | 176 return "$object"; |
186 } catch (e) { | 177 } catch (e) { |
187 return "Error when converting ${object.runtimeType} to string."; | 178 return "Error when converting ${object.runtimeType} to string."; |
188 } | 179 } |
189 } | 180 } |
OLD | NEW |