Skip to content

Commit 8b61074

Browse files
authored
improve dwds eval error reporting (#338)
1 parent f750e21 commit 8b61074

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

dwds/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.1
2+
3+
- Improve error reporting for evals, give the full JS eval in the error message
4+
so it can be more easily reproduced.
5+
16
## 0.3.0
27

38
- Change the exposed type on DebugService to VmServiceInterface

dwds/lib/src/chrome_proxy_service.dart

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,28 @@ require("dart_sdk").developer.invokeExtension(
251251
throw UnsupportedError(
252252
'Evaluate is only supported when `targetId` is a library.');
253253
}
254-
var result = await tabConnection.runtime.evaluate('''
254+
var evalExpression = '''
255255
(function() {
256256
${_getLibrarySnippet(library.uri)};
257257
return library.$expression;
258258
})();
259-
''');
259+
''';
260+
var result = await tabConnection.runtime.sendCommand('Runtime.evaluate',
261+
params: {'expression': evalExpression, 'returnByValue': true});
262+
_handleErrorIfPresent(result,
263+
evalContents: evalExpression,
264+
additionalDetails: {
265+
'Dart expression': expression,
266+
'scope': scope,
267+
});
268+
var remoteObject =
269+
RemoteObject(result.result['result'] as Map<String, dynamic>);
260270

261271
String kind;
262272
var classRef = ClassRef()
263-
..id = 'dart:core:${result.type}'
264-
..name = result.type;
265-
switch (result.type) {
273+
..id = 'dart:core:${remoteObject.type}'
274+
..name = remoteObject.type;
275+
switch (remoteObject.type) {
266276
case 'string':
267277
kind = InstanceKind.kString;
268278
break;
@@ -273,11 +283,12 @@ require("dart_sdk").developer.invokeExtension(
273283
kind = InstanceKind.kBool;
274284
break;
275285
default:
276-
throw UnsupportedError('Unsupported response type ${result.type}');
286+
throw UnsupportedError(
287+
'Unsupported response type ${remoteObject.type}');
277288
}
278289

279290
return InstanceRef()
280-
..valueAsString = '${result.value}'
291+
..valueAsString = '${remoteObject.value}'
281292
..classRef = classRef
282293
..kind = kind;
283294
}
@@ -788,11 +799,13 @@ const _stdoutTypes = ['log', 'info', 'warning'];
788799

789800
/// Throws an [ExceptionDetails] object if `exceptionDetails` is present on the
790801
/// result.
791-
void _handleErrorIfPresent(WipResponse response, {String evalContents}) {
802+
void _handleErrorIfPresent(WipResponse response,
803+
{String evalContents, Object additionalDetails}) {
792804
if (response.result.containsKey('exceptionDetails')) {
793805
throw ChromeDebugException(
794806
response.result['exceptionDetails'] as Map<String, dynamic>,
795-
evalContents: evalContents);
807+
evalContents: evalContents,
808+
additionalDetails: additionalDetails);
796809
}
797810
}
798811

@@ -818,11 +831,14 @@ String _getLibrarySnippet(String libraryUri) => '''
818831
''';
819832

820833
class ChromeDebugException extends ExceptionDetails implements Exception {
834+
/// Optional, additional information about the exception.
835+
final Object additionalDetails;
836+
821837
/// Optional, the exact contents of the eval that was attempted.
822838
final String evalContents;
823839

824840
ChromeDebugException(Map<String, dynamic> exceptionDetails,
825-
{this.evalContents})
841+
{this.additionalDetails, this.evalContents})
826842
: super(exceptionDetails);
827843

828844
@override
@@ -839,7 +855,10 @@ class ChromeDebugException extends ExceptionDetails implements Exception {
839855
description.writeln(' value: ${exception.value}');
840856
}
841857
if (evalContents != null) {
842-
description.writeln('attempted eval: `$evalContents`');
858+
description.writeln('attempted JS eval: `$evalContents`');
859+
}
860+
if (additionalDetails != null) {
861+
description.writeln('additional details:\n $additionalDetails');
843862
}
844863
return description.toString();
845864
}

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dwds
2-
version: 0.3.0
2+
version: 0.3.1
33
author: Dart Team <misc@dartlang.org>
44
homepage: https://github.com/dart-lang/webdev/tree/master/dwds
55
description: >-

0 commit comments

Comments
 (0)