From 7cac006f47af351a7c626d947f8d8495166d6883 Mon Sep 17 00:00:00 2001 From: Junfeng Wu Date: Fri, 30 Jun 2023 14:34:37 +0800 Subject: [PATCH] fix: start code from 0 Otherwise, if not specified, CANCELED will be the default code. The fixed error code is also more consistent with gRPC code. --- codes.go | 2 +- format_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codes.go b/codes.go index d39c590..750f132 100644 --- a/codes.go +++ b/codes.go @@ -12,7 +12,7 @@ type Code int // These are common impact error codes that are found throughout our services. const ( // The operation was cancelled, typically by the caller. - CodeCanceled Code = iota + CodeCanceled Code = iota + 1 // Unknown error. For example, this error may be returned when a 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. CodeUnknown // The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the system (e.g., a malformed file name). diff --git a/format_test.go b/format_test.go index b1af818..57f0772 100644 --- a/format_test.go +++ b/format_test.go @@ -127,7 +127,7 @@ func TestFormatStr(t *testing.T) { }, "external error": { input: errors.New("external error"), - output: "code(canceled) external error", + output: "code(unknown) external error", }, // This is the expected behavior, since this error does not hold any information "empty error": { @@ -175,7 +175,7 @@ func TestInvertedFormatStr(t *testing.T) { }, "external error": { input: errors.New("external error"), - output: "external error code(canceled) ", + output: "external error code(unknown) ", }, "empty wrapped external error": { input: eris.WithCode(eris.Wrap(errors.New("some err"), "additional context"), eris.CodeUnknown),