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

Commit

Permalink
Allow a null result (#77)
Browse files Browse the repository at this point in the history
Fixes #76

Add missing nullable annotation on the `result` variable and a test
which fails if the variable is non-nullable.
  • Loading branch information
natebosch authored May 1, 2021
1 parent 62fd274 commit 7e00f89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.1-dev

* Fix a bug where a `null` result to a request caused an exception.

## 3.0.0

* Migrate to null safety.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Server {
var method = _methods[name];
method ??= _tryFallbacks;

Object result;
Object? result;
if (method is ZeroArgumentFunction) {
if (request.containsKey('params')) {
throw RpcException.invalidParams('No parameters are allowed for '
Expand Down
9 changes: 9 additions & 0 deletions test/server/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ void main() {
completion(equals({'jsonrpc': '2.0', 'result': 'foo', 'id': 1234})));
});

test('Allows a `null` result', () {
controller.server.registerMethod('foo', () => null);

expect(
controller
.handleRequest({'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}),
completion(equals({'jsonrpc': '2.0', 'result': null, 'id': 1234})));
});

test('a method that takes no parameters rejects parameters', () {
controller.server.registerMethod('foo', () => 'foo');

Expand Down

0 comments on commit 7e00f89

Please sign in to comment.