@@ -7,22 +7,24 @@ import 'dart:io';
77
88import 'package:http/http.dart' as http;
99import 'package:stack_trace/stack_trace.dart' ;
10- import 'package:usage/usage.dart' ;
1110
1211// Reporting disabled until we're set up on the backend.
1312const bool CRASH_REPORTING_DISABLED = true ;
1413
14+ /// Tells crash backend that this is a Dart error (as opposed to, say, Java).
15+ const String _dartTypeId = 'DartError' ;
16+
1517/// Crash backend host.
1618const String _crashServerHost = 'clients2.google.com' ;
1719
1820/// Path to the crash servlet.
19- const String _crashEndpointPath = '/cr/report' ; // or, staging_report
21+ const String _crashEndpointPath = '/cr/report' ; // or, ' staging_report'
2022
2123/// The field corresponding to the multipart/form-data file attachment where
2224/// crash backend expects to find the Dart stack trace.
2325const String _stackTraceFileField = 'DartError' ;
2426
25- /// The name of the file attached as [stackTraceFileField ] .
27+ /// The name of the file attached as [_stackTraceFileField ] .
2628///
2729/// The precise value is not important. It is ignored by the crash back end, but
2830/// it must be supplied in the request.
@@ -36,41 +38,43 @@ class CrashReportSender {
3638 scheme: 'https' , host: _crashServerHost, path: _crashEndpointPath);
3739
3840 final String crashProductId;
39- final Analytics analytics ;
41+ final EnablementCallback shouldSend ;
4042 final http.Client _httpClient;
4143
4244 /// Create a new [CrashReportSender] , using the data from the given
4345 /// [Analytics] instance.
44- CrashReportSender (this .crashProductId, this .analytics ,
46+ CrashReportSender (this .crashProductId, this .shouldSend ,
4547 {http.Client httpClient})
4648 : _httpClient = httpClient ?? new http.Client ();
4749
4850 /// Sends one crash report.
4951 ///
5052 /// The report is populated from data in [error] and [stackTrace] .
5153 Future sendReport (dynamic error, {StackTrace stackTrace}) async {
52- if (! analytics.enabled || CRASH_REPORTING_DISABLED ) {
54+ if (! shouldSend () || CRASH_REPORTING_DISABLED ) {
5355 return ;
5456 }
5557
5658 try {
59+ final String dartVersion = Platform .version.split (' ' ).first;
60+
5761 final Uri uri = _baseUri.replace (
5862 queryParameters: < String , String > {
59- 'product' : analytics.trackingId ,
60- 'version' : analytics.applicationVersion ,
63+ 'product' : crashProductId ,
64+ 'version' : dartVersion ,
6165 },
6266 );
6367
6468 final http.MultipartRequest req = new http.MultipartRequest ('POST' , uri);
65- req.fields['uuid' ] = analytics.clientId;
6669 req.fields['product' ] = crashProductId;
67- req.fields['version' ] = analytics.applicationVersion ;
70+ req.fields['version' ] = dartVersion ;
6871 req.fields['osName' ] = Platform .operatingSystem;
6972 req.fields['osVersion' ] = Platform .operatingSystemVersion;
70- req.fields['type' ] = 'DartError' ;
73+ req.fields['type' ] = _dartTypeId ;
7174 req.fields['error_runtime_type' ] = '${error .runtimeType }' ;
75+ req.fields['error_message' ] = '$error ' ;
7276
73- final Chain chain = new Chain .parse (stackTrace. toString () );
77+ final Chain chain = new Chain .forTrace (stackTrace);
7478 req.files.add (new http.MultipartFile .fromString (
7579 _stackTraceFileField, chain.terse.toString (),
7680 filename: _stackTraceFilename));
@@ -94,3 +98,7 @@ class CrashReportSender {
9498 _httpClient.close ();
9599 }
96100}
101+
102+ /// A typedef to allow crash reporting to query as to whether it should send a
103+ /// crash report.
104+ typedef bool EnablementCallback ();
0 commit comments