[dds/dap] Improve display of errors calling toString() in debug views

Fixes https://github.com/Dart-Code/Dart-Code/issues/4400.

Change-Id: I46b36bcacdd0f8a33f296569fbc2e4ebece9d0f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284701
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Danny Tuppeny
2023-02-22 17:11:12 +00:00
committed by Commit Queue
parent 67e7c96962
commit 3d39175f5d
2 changed files with 37 additions and 0 deletions
@@ -369,6 +369,11 @@ class ProtocolConverter {
allowCallingToString: allowCallingToString,
format: format,
);
} else if (response is vm.ErrorRef) {
final errorMessage = response.message;
return errorMessage != null
? _adapter.extractUnhandledExceptionMessage(errorMessage)
: response.kind ?? '<unknown error>';
} else if (response is vm.Sentinel) {
return '<sentinel>';
} else {
@@ -577,6 +577,38 @@ void main() {
);
});
test('handles errors in toString() on custom classes', () async {
final client = dap.client;
final testFile = dap.createTestFile('''
class Foo {
toString() => throw UnimplementedError('NYI!');
}
void main() {
final myVariable = Foo();
print('Hello!'); $breakpointMarker
}
''');
final breakpointLine = lineWith(testFile, breakpointMarker);
final stop = await client.hitBreakpoint(
testFile,
breakpointLine,
launch: () => client.launch(
testFile.path,
evaluateToStringInDebugViews: true,
),
);
await client.expectScopeVariables(
await client.getTopFrameId(stop.threadId!),
'Locals',
r'''
myVariable: Foo (UnimplementedError: NYI!), eval: myVariable
''',
);
});
test('does not use toString() result if "Instance of Foo"', () async {
// When evaluateToStringInDebugViews=true, we should discard the result of
// calling toString() when it's just 'Instance of Foo' because we're already