Skip to content

Commit

Permalink
go/common/errors: expose all grpc errors as coded
Browse files Browse the repository at this point in the history
  • Loading branch information
nhynes committed Jun 25, 2021
1 parent b71bbb5 commit 5a0762b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/4067.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose runtime query error details to clients
6 changes: 5 additions & 1 deletion go/common/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ func New(module string, code uint32, msg string) error {
func FromCode(module string, code uint32, context string) error {
err, exists := registeredErrors.Load(errorKey(module, code))
if !exists || err == errUnknownError {
return errors.New(context)
return WithContext(&codedError{
module: module,
code: code,
msg: context,
}, context)
}

return WithContext(err.(*codedError), context)
Expand Down
7 changes: 3 additions & 4 deletions go/common/errors/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package errors

import (
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -72,7 +71,7 @@ func TestErrors(t *testing.T) {

// Unknown module and code.
err = FromCode("test/does-not-exist", 5, "")
require.Equal(err, errors.New(""))
err = FromCode("test/errors", 3, "")
require.Equal(err, errors.New(""))
require.Equal(err, New("test/does-not-exist", 5, ""))
err = FromCode("test/errors", 3, "a test error occurred")
require.Equal(err, WithContext(New("test/errors", 3, "a test error occurred"), "a test error occurred"))
}

0 comments on commit 5a0762b

Please sign in to comment.