Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add the method name to pending request errors (#26)
Browse files Browse the repository at this point in the history
This makes it easier to debug pending request errors.
  • Loading branch information
nex3 authored Jan 17, 2018
1 parent 35c33ba commit ba1765d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.7

* When a `Client` is closed before a request completes, the error sent to that
request's `Future` now includes the request method to aid in debugging.

## 2.0.6

* Internal changes only.
Expand Down
10 changes: 7 additions & 3 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class Client {
_manager.done.whenComplete(() {
for (var request in _pendingRequests.values) {
request.completer.completeError(
new StateError("The client closed with pending requests."),
new StateError(
'The client closed with pending request "${request.method}".'),
StackTrace.current);
}
_pendingRequests.clear();
Expand Down Expand Up @@ -106,7 +107,7 @@ class Client {
_send(method, parameters, id);

var completer = new Completer.sync();
_pendingRequests[id] = new _Request(completer, new Chain.current());
_pendingRequests[id] = new _Request(method, completer, new Chain.current());
return completer.future;
}

Expand Down Expand Up @@ -213,11 +214,14 @@ class Client {

/// A pending request to the server.
class _Request {
/// THe method that was sent.
final String method;

/// The completer to use to complete the response future.
final Completer completer;

/// The stack chain from where the request was made.
final Chain chain;

_Request(this.completer, this.chain);
_Request(this.method, this.completer, this.chain);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_rpc_2
version: 2.0.6
version: 2.0.7
author: Dart Team <[email protected]>
description: An implementation of the JSON-RPC 2.0 spec.
homepage: http://github.com/dart-lang/json_rpc_2
Expand Down

0 comments on commit ba1765d

Please sign in to comment.