diff --git a/CHANGELOG.md b/CHANGELOG.md index 45ea736..cd28d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.3-wip + +* Add const constructor to `GrpcError` fixing #606. + ## 3.2.2 * Remove `base` qualifier on `ResponseStream`. diff --git a/lib/src/shared/status.dart b/lib/src/shared/status.dart index 597afce..5ab3a05 100644 --- a/lib/src/shared/status.dart +++ b/lib/src/shared/status.dart @@ -151,7 +151,7 @@ class StatusCode { } } -class GrpcError implements Exception { +final class GrpcError implements Exception { final int code; final String? message; final Object? rawResponse; @@ -159,16 +159,16 @@ class GrpcError implements Exception { final List? details; /// Custom error code. - GrpcError.custom(this.code, + const GrpcError.custom(this.code, [this.message, this.details, this.rawResponse, this.trailers = const {}]); /// The operation completed successfully. - GrpcError.ok([this.message, this.details, this.rawResponse]) + const GrpcError.ok([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.ok; /// The operation was cancelled (typically by the caller). - GrpcError.cancelled([this.message, this.details, this.rawResponse]) + const GrpcError.cancelled([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.cancelled; @@ -176,7 +176,7 @@ class GrpcError implements Exception { /// Status value received from another address space belongs to an error-space /// that is not known in this address space. Also errors raised by APIs that /// do not return enough error information may be converted to this error. - GrpcError.unknown([this.message, this.details, this.rawResponse]) + const GrpcError.unknown([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.unknown; @@ -184,7 +184,8 @@ class GrpcError implements Exception { /// [failedPrecondition]. [invalidArgument] indicates arguments that are /// problematic regardless of the state of the system (e.g., a malformed file /// name). - GrpcError.invalidArgument([this.message, this.details, this.rawResponse]) + const GrpcError.invalidArgument( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.invalidArgument; @@ -193,18 +194,19 @@ class GrpcError implements Exception { /// operation has completed successfully. For example, a successful response /// from a server could have been delayed long enough for the deadline to /// expire. - GrpcError.deadlineExceeded([this.message, this.details, this.rawResponse]) + const GrpcError.deadlineExceeded( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.deadlineExceeded; /// Some requested entity (e.g., file or directory) was not found. - GrpcError.notFound([this.message, this.details, this.rawResponse]) + const GrpcError.notFound([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.notFound; /// Some entity that we attempted to create (e.g., file or directory) already /// exists. - GrpcError.alreadyExists([this.message, this.details, this.rawResponse]) + const GrpcError.alreadyExists([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.alreadyExists; @@ -213,13 +215,15 @@ class GrpcError implements Exception { /// some resource (use [resourceExhausted] instead for those errors). /// [permissionDenied] must not be used if the caller cannot be identified /// (use [unauthenticated] instead for those errors). - GrpcError.permissionDenied([this.message, this.details, this.rawResponse]) + const GrpcError.permissionDenied( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.permissionDenied; /// Some resource has been exhausted, perhaps a per-user quota, or perhaps the /// entire file system is out of space. - GrpcError.resourceExhausted([this.message, this.details, this.rawResponse]) + const GrpcError.resourceExhausted( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.resourceExhausted; @@ -237,7 +241,8 @@ class GrpcError implements Exception { /// because the directory is non-empty, [failedPrecondition] should be /// returned since the client should not retry unless they have first /// fixed up the directory by deleting files from it. - GrpcError.failedPrecondition([this.message, this.details, this.rawResponse]) + const GrpcError.failedPrecondition( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.failedPrecondition; @@ -246,7 +251,7 @@ class GrpcError implements Exception { /// /// See litmus test above for deciding between [failedPrecondition], /// [aborted], and [unavailable]. - GrpcError.aborted([this.message, this.details, this.rawResponse]) + const GrpcError.aborted([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.aborted; @@ -263,19 +268,19 @@ class GrpcError implements Exception { /// [outOfRange]. We recommend using [outOfRange] (the more specific error) /// when it applies so that callers who are iterating through a space can /// easily look for an [outOfRange] error to detect when they are done. - GrpcError.outOfRange([this.message, this.details, this.rawResponse]) + const GrpcError.outOfRange([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.outOfRange; /// Operation is not implemented or not supported/enabled in this service. - GrpcError.unimplemented([this.message, this.details, this.rawResponse]) + const GrpcError.unimplemented([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.unimplemented; /// 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( + const GrpcError.internal( [this.message, this.details, this.rawResponse, this.trailers]) : code = StatusCode.internal; @@ -284,18 +289,19 @@ class GrpcError implements Exception { /// /// See litmus test above for deciding between [failedPrecondition], /// [aborted], and [unavailable]. - GrpcError.unavailable([this.message, this.details, this.rawResponse]) + const GrpcError.unavailable([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.unavailable; /// Unrecoverable data loss or corruption. - GrpcError.dataLoss([this.message, this.details, this.rawResponse]) + const GrpcError.dataLoss([this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.dataLoss; /// The request does not have valid authentication credentials for the /// operation. - GrpcError.unauthenticated([this.message, this.details, this.rawResponse]) + const GrpcError.unauthenticated( + [this.message, this.details, this.rawResponse]) : trailers = const {}, code = StatusCode.unauthenticated; diff --git a/pubspec.yaml b/pubspec.yaml index 0129f38..88523a7 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: 3.2.2 +version: 3.2.3-wip repository: https://github.com/grpc/grpc-dart