Adding source to error logs (#556)
diff --git a/lib/src/common_server_impl.dart b/lib/src/common_server_impl.dart
index 5f13521..7a4d555 100644
--- a/lib/src/common_server_impl.dart
+++ b/lib/src/common_server_impl.dart
@@ -195,7 +195,7 @@
throw BadRequest('Missing parameter: \'source\'');
}
- return _format(request.source, offset: request.offset ?? 0);
+ return _format(request.source, request.offset ?? 0);
}
Future<proto.DocumentResponse> document(proto.SourceRequest request) {
@@ -224,7 +224,7 @@
log.info('PERF: Analyzed $lineCount lines of Dart in ${ms}ms.');
return results;
} catch (e, st) {
- log.severe('Error during analyze', e, st);
+ log.severe('Error during _analyze on "$source"', e, st);
await restart();
rethrow;
}
@@ -234,30 +234,31 @@
String source, {
bool returnSourceMap = false,
}) async {
- await _checkPackageReferencesInitFlutterWeb(source);
+ try {
+ await _checkPackageReferencesInitFlutterWeb(source);
- final sourceHash = _hashSource(source);
- final memCacheKey = '%%COMPILE:v0'
- ':returnSourceMap:$returnSourceMap:source:$sourceHash';
+ final sourceHash = _hashSource(source);
+ final memCacheKey = '%%COMPILE:v0'
+ ':returnSourceMap:$returnSourceMap:source:$sourceHash';
- final result = await checkCache(memCacheKey);
- if (result != null) {
- log.info('CACHE: Cache hit for compileDart2js');
- final resultObj = const JsonDecoder().convert(result);
- final response = proto.CompileResponse()
- ..result = resultObj['compiledJS'] as String;
- if (resultObj['sourceMap'] != null) {
- response.sourceMap = resultObj['sourceMap'] as String;
+ final result = await checkCache(memCacheKey);
+ if (result != null) {
+ log.info('CACHE: Cache hit for compileDart2js');
+ final resultObj = const JsonDecoder().convert(result);
+ final response = proto.CompileResponse()
+ ..result = resultObj['compiledJS'] as String;
+ if (resultObj['sourceMap'] != null) {
+ response.sourceMap = resultObj['sourceMap'] as String;
+ }
+ return response;
}
- return response;
- }
- log.info('CACHE: MISS for compileDart2js');
- final watch = Stopwatch()..start();
+ log.info('CACHE: MISS for compileDart2js');
+ final watch = Stopwatch()..start();
- return compiler
- .compile(source, returnSourceMap: returnSourceMap)
- .then((CompilationResults results) {
+ final results =
+ await compiler.compile(source, returnSourceMap: returnSourceMap);
+
if (results.hasOutput) {
final lineCount = source.split('\n').length;
final outputSize = (results.compiledJS.length / 1024).ceil();
@@ -283,33 +284,35 @@
final errors = problems.map(_printCompileProblem).join('\n');
throw BadRequest(errors);
}
- }).catchError((dynamic e, dynamic st) {
+ } catch (e, st) {
if (e is! BadRequest) {
- log.severe('Error during compile (dart2js): $e\n$st');
+ log.severe('Error during compile (dart2js) on "$source"', e, st);
}
- throw e;
- });
+ rethrow;
+ }
}
Future<proto.CompileDDCResponse> _compileDDC(String source) async {
- await _checkPackageReferencesInitFlutterWeb(source);
+ try {
+ await _checkPackageReferencesInitFlutterWeb(source);
- final sourceHash = _hashSource(source);
- final memCacheKey = '%%COMPILE_DDC:v0:source:$sourceHash';
+ final sourceHash = _hashSource(source);
+ final memCacheKey = '%%COMPILE_DDC:v0:source:$sourceHash';
- final result = await checkCache(memCacheKey);
- if (result != null) {
- log.info('CACHE: Cache hit for compileDDC');
- final resultObj = const JsonDecoder().convert(result);
- return proto.CompileDDCResponse()
- ..result = resultObj['compiledJS'] as String
- ..modulesBaseUrl = resultObj['modulesBaseUrl'] as String;
- }
+ final result = await checkCache(memCacheKey);
+ if (result != null) {
+ log.info('CACHE: Cache hit for compileDDC');
+ final resultObj = const JsonDecoder().convert(result);
+ return proto.CompileDDCResponse()
+ ..result = resultObj['compiledJS'] as String
+ ..modulesBaseUrl = resultObj['modulesBaseUrl'] as String;
+ }
- log.info('CACHE: MISS for compileDDC');
- final watch = Stopwatch()..start();
+ log.info('CACHE: MISS for compileDDC');
+ final watch = Stopwatch()..start();
- return compiler.compileDDC(source).then((DDCCompilationResults results) {
+ final results = await compiler.compileDDC(source);
+
if (results.hasOutput) {
final lineCount = source.split('\n').length;
final outputSize = (results.compiledJS.length / 1024).ceil();
@@ -331,12 +334,12 @@
final errors = problems.map(_printCompileProblem).join('\n');
throw BadRequest(errors);
}
- }).catchError((dynamic e, dynamic st) {
+ } catch (e, st) {
if (e is! BadRequest) {
- log.severe('Error during compile (DDC): $e\n$st');
+ log.severe('Error during compile (DDC) on "$source"', e, st);
}
- throw e;
- });
+ rethrow;
+ }
}
Future<proto.DocumentResponse> _document(String source, int offset) async {
@@ -350,7 +353,7 @@
log.info('PERF: Computed dartdoc in ${watch.elapsedMilliseconds}ms.');
return proto.DocumentResponse()..info.addAll(docInfo);
} catch (e, st) {
- log.severe('Error during dartdoc', e, st);
+ log.severe('Error during _document on "$source" at $offset', e, st);
await restart();
rethrow;
}
@@ -376,39 +379,57 @@
log.info('PERF: Computed completions in ${watch.elapsedMilliseconds}ms.');
return response;
} catch (e, st) {
- log.severe('Error during _complete', e, st);
+ log.severe('Error during _complete on "$source" at $offset', e, st);
await restart();
rethrow;
}
}
Future<proto.FixesResponse> _fixes(String source, int offset) async {
- await _checkPackageReferencesInitFlutterWeb(source);
+ try {
+ await _checkPackageReferencesInitFlutterWeb(source);
- final watch = Stopwatch()..start();
- final response =
- await getCorrectAnalysisServer(source).getFixes(source, offset);
- log.info('PERF: Computed fixes in ${watch.elapsedMilliseconds}ms.');
- return response;
+ final watch = Stopwatch()..start();
+ final response =
+ await getCorrectAnalysisServer(source).getFixes(source, offset);
+ log.info('PERF: Computed fixes in ${watch.elapsedMilliseconds}ms.');
+ return response;
+ } catch (e, st) {
+ log.severe('Error during _fixes on "$source" at $offset', e, st);
+ await restart();
+ rethrow;
+ }
}
Future<proto.AssistsResponse> _assists(String source, int offset) async {
- await _checkPackageReferencesInitFlutterWeb(source);
+ try {
+ await _checkPackageReferencesInitFlutterWeb(source);
- final watch = Stopwatch()..start();
- final response =
- await getCorrectAnalysisServer(source).getAssists(source, offset);
- log.info('PERF: Computed assists in ${watch.elapsedMilliseconds}ms.');
- return response;
+ final watch = Stopwatch()..start();
+ final response =
+ await getCorrectAnalysisServer(source).getAssists(source, offset);
+ log.info('PERF: Computed assists in ${watch.elapsedMilliseconds}ms.');
+ return response;
+ } catch (e, st) {
+ log.severe('Error during _assists on "$source" at $offset', e, st);
+ await restart();
+ rethrow;
+ }
}
- Future<proto.FormatResponse> _format(String source, {int offset}) async {
- final watch = Stopwatch()..start();
+ Future<proto.FormatResponse> _format(String source, int offset) async {
+ try {
+ final watch = Stopwatch()..start();
- final response =
- await getCorrectAnalysisServer(source).format(source, offset);
- log.info('PERF: Computed format in ${watch.elapsedMilliseconds}ms.');
- return response;
+ final response =
+ await getCorrectAnalysisServer(source).format(source, offset);
+ log.info('PERF: Computed format in ${watch.elapsedMilliseconds}ms.');
+ return response;
+ } catch (e, st) {
+ log.severe('Error during _format on "$source" at $offset', e, st);
+ await restart();
+ rethrow;
+ }
}
Future<String> checkCache(String query) => cache.get(query);