[dds/dap] Improve reporting of failed requests in DAP tests

This improves the failure messages that will show in tests if a DAP request unexpectedly fails.

Before:

```
Instance of 'Response'
```

After:

```
  Request "evaluate" failed:
  {
      "seq": 17,
      "type": "response",
      "body": {
          "error": {
              "format": "{message}",
              "id": 1,
              "showUser": true,
              "variables": {
                  "message": "This is a test failure",
                  "stack": "#0      DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:1046:5)\n#1      (SNIP)\n"
              }
          }
      },
      "command": "evaluate",
      "message": "This is a test failure",
      "request_seq": 8,
      "success": false
  }
```

Might help diagnose https://github.com/dart-lang/sdk/issues/55705.

Change-Id: If9edad16090a8bd09e22dd9b772401763d281f8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366640
Commit-Queue: Helin Shiah <helinx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Helin Shiah <helinx@google.com>
This commit is contained in:
Danny Tuppeny 2024-05-15 22:17:18 +00:00 committed by Commit Queue
parent 38d7d5d663
commit 5a6b2421bf

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:collection/collection.dart';
@ -549,7 +550,7 @@ class DapTestClient {
if (message.success || pendingRequest.allowFailure) {
completer.complete(message);
} else {
completer.completeError(message);
completer.completeError(RequestException(pendingRequest.name, message));
}
} else if (message is Event && !_eventController.isClosed) {
_eventController.add(message);
@ -1310,3 +1311,19 @@ extension DapTestClientExtension on DapTestClient {
return body;
}
}
/// Represents an error message returned from the debug adapter in response
/// to a request.
class RequestException implements Exception {
/// The name of the request that was made by the client.
final String requestName;
/// The raw message that came from back from the adapter.
final ProtocolMessage message;
RequestException(this.requestName, this.message);
@override
String toString() => 'Request "$requestName" failed:\n'
'${JsonEncoder.withIndent(' ').convert(message.toJson())}';
}