Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.1

- Improve error reporting for evals, give the full JS eval in the error message
so it can be more easily reproduced.

## 0.3.0

- Change the exposed type on DebugService to VmServiceInterface
Expand Down
41 changes: 30 additions & 11 deletions dwds/lib/src/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,28 @@ require("dart_sdk").developer.invokeExtension(
throw UnsupportedError(
'Evaluate is only supported when `targetId` is a library.');
}
var result = await tabConnection.runtime.evaluate('''
var evalExpression = '''
(function() {
${_getLibrarySnippet(library.uri)};
return library.$expression;
})();
''');
''';
var result = await tabConnection.runtime.sendCommand('Runtime.evaluate',
params: {'expression': evalExpression, 'returnByValue': true});
_handleErrorIfPresent(result,
evalContents: evalExpression,
additionalDetails: {
'Dart expression': expression,
'scope': scope,
});
var remoteObject =
RemoteObject(result.result['result'] as Map<String, dynamic>);

String kind;
var classRef = ClassRef()
..id = 'dart:core:${result.type}'
..name = result.type;
switch (result.type) {
..id = 'dart:core:${remoteObject.type}'
..name = remoteObject.type;
switch (remoteObject.type) {
case 'string':
kind = InstanceKind.kString;
break;
Expand All @@ -273,11 +283,12 @@ require("dart_sdk").developer.invokeExtension(
kind = InstanceKind.kBool;
break;
default:
throw UnsupportedError('Unsupported response type ${result.type}');
throw UnsupportedError(
'Unsupported response type ${remoteObject.type}');
}

return InstanceRef()
..valueAsString = '${result.value}'
..valueAsString = '${remoteObject.value}'
..classRef = classRef
..kind = kind;
}
Expand Down Expand Up @@ -788,11 +799,13 @@ const _stdoutTypes = ['log', 'info', 'warning'];

/// Throws an [ExceptionDetails] object if `exceptionDetails` is present on the
/// result.
void _handleErrorIfPresent(WipResponse response, {String evalContents}) {
void _handleErrorIfPresent(WipResponse response,
{String evalContents, Object additionalDetails}) {
if (response.result.containsKey('exceptionDetails')) {
throw ChromeDebugException(
response.result['exceptionDetails'] as Map<String, dynamic>,
evalContents: evalContents);
evalContents: evalContents,
additionalDetails: additionalDetails);
}
}

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

class ChromeDebugException extends ExceptionDetails implements Exception {
/// Optional, additional information about the exception.
final Object additionalDetails;

/// Optional, the exact contents of the eval that was attempted.
final String evalContents;

ChromeDebugException(Map<String, dynamic> exceptionDetails,
{this.evalContents})
{this.additionalDetails, this.evalContents})
: super(exceptionDetails);

@override
Expand All @@ -839,7 +855,10 @@ class ChromeDebugException extends ExceptionDetails implements Exception {
description.writeln(' value: ${exception.value}');
}
if (evalContents != null) {
description.writeln('attempted eval: `$evalContents`');
description.writeln('attempted JS eval: `$evalContents`');
}
if (additionalDetails != null) {
description.writeln('additional details:\n $additionalDetails');
}
return description.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dwds
version: 0.3.0
version: 0.3.1
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev/tree/master/dwds
description: >-
Expand Down