Make constructors of `GrpcError` const (#638)

* Make constructors of `GrpcError` const

* Update CHANGELOG.md

Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

* Update pubspec.yaml

Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

---------

Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
This commit is contained in:
Moritz 2023-06-21 10:48:55 -04:00 committed by GitHub
parent 870ac192fa
commit aae487d12f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 20 deletions

View File

@ -1,3 +1,7 @@
## 3.2.3-wip
* Add const constructor to `GrpcError` fixing #606.
## 3.2.2
* Remove `base` qualifier on `ResponseStream`.

View File

@ -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<GeneratedMessage>? 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;

View File

@ -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