diff --git a/CHANGELOG.md b/CHANGELOG.md index 82c264f..36a4186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.3 + +* GrpcError now implements Exception to indicate it can be reasonably handled. + ## 2.0.2 * Fix computation of the audience given to metadata providers to include the scheme. diff --git a/lib/src/client/http2_connection.dart b/lib/src/client/http2_connection.dart index c6b0df4..1698555 100644 --- a/lib/src/client/http2_connection.dart +++ b/lib/src/client/http2_connection.dart @@ -73,8 +73,7 @@ class Http2ClientConnection implements connection.ClientConnection { var socket = await Socket.connect(host, port); if (_state == ConnectionState.shutdown) { socket.destroy(); - // TODO(sigurdm): Throw something nicer... - throw 'Shutting down'; + throw _ShutdownException(); } final securityContext = credentials.securityContext; if (securityContext != null) { @@ -84,8 +83,7 @@ class Http2ClientConnection implements connection.ClientConnection { onBadCertificate: _validateBadCertificate); if (_state == ConnectionState.shutdown) { socket.destroy(); - // TODO(sigurdm): Throw something nicer... - throw 'Shutting down'; + throw _ShutdownException(); } } socket.done.then((_) => _handleSocketClosed()); @@ -275,3 +273,5 @@ class Http2ClientConnection implements connection.ClientConnection { return validator(certificate, authority); } } + +class _ShutdownException implements Exception {} diff --git a/lib/src/shared/message.dart b/lib/src/shared/message.dart index 0d97c0a..9a4f199 100644 --- a/lib/src/shared/message.dart +++ b/lib/src/shared/message.dart @@ -41,7 +41,7 @@ class GrpcMessageSink extends Sink { @override void add(GrpcMessage data) { if (message != null) { - throw 'Too many messages received!'; + throw StateError('Too many messages received!'); } message = data; } @@ -49,7 +49,7 @@ class GrpcMessageSink extends Sink { @override void close() { if (message == null) { - throw 'No messages received!'; + throw StateError('No messages received!'); } } } diff --git a/lib/src/shared/status.dart b/lib/src/shared/status.dart index 4879cd3..9c0067e 100644 --- a/lib/src/shared/status.dart +++ b/lib/src/shared/status.dart @@ -117,7 +117,7 @@ class StatusCode { static const unauthenticated = 16; } -class GrpcError { +class GrpcError implements Exception { final int code; final String message; @@ -214,6 +214,7 @@ class GrpcError { /// Internal errors. Means some invariants expected by underlying system has /// been broken. If you see one of these errors, something is very broken. + // TODO(sigurdm): This should probably not be an [Exception]. GrpcError.internal([this.message]) : code = StatusCode.internal; /// The service is currently unavailable. This is a most likely a transient diff --git a/pubspec.yaml b/pubspec.yaml index 44d9dd1..2b4e613 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: grpc description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. -version: 2.0.2 +version: 2.0.3 author: Dart Team homepage: https://github.com/dart-lang/grpc-dart