Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions go/errorutil/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func PermissionDenied(format string, args ...any) error {
return connect.NewError(connect.CodePermissionDenied, fmt.Errorf(format, args...))
}

// Unimplemented creates a new Unimplemented error (Connect Code 12) with a formatted error message.
func Unimplemented(format string, args ...any) error {
return connect.NewError(connect.CodeUnimplemented, fmt.Errorf(format, args...))
}

// NewNotFound creates a new Not Found error (Connect Code 5) from an underlying error.
func NewNotFound(err error) error {
return connect.NewError(connect.CodeNotFound, err)
Expand Down Expand Up @@ -142,6 +147,11 @@ func NewPermissionDenied(err error) error {
return connect.NewError(connect.CodePermissionDenied, err)
}

// NewUnimplemented creates a new Unimplemented error (Connect Code 12) from an underlying error.
func NewUnimplemented(err error) error {
return connect.NewError(connect.CodeUnimplemented, err)
}

// IsNotFound reports whether the error is a Not Found error (Connect Code 5).
func IsNotFound(err error) bool {
connectErr := Convert(err)
Expand Down Expand Up @@ -196,6 +206,12 @@ func IsPermissionDenied(err error) bool {
return connectErr.Code() == connect.CodePermissionDenied
}

// IsUnimplemented reports whether the error is a Unimplemented error (Connect Code 12).
func IsUnimplemented(err error) bool {
connectErr := Convert(err)
return connectErr.Code() == connect.CodeUnimplemented
}

// WrapConnectErr wraps the error into a connect.Error with the given code if it is not already a connect.Error.
// If the error is already a *connect.Error, it returns it unchanged.
func WrapConnectErr(c connect.Code, underlying error) *connect.Error {
Expand Down
5 changes: 5 additions & 0 deletions go/errorutil/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func TestIsErrFns(t *testing.T) {
errFn: IsUnauthenticated,
code: connect.CodeUnauthenticated,
},
{
name: "unimplemented",
errFn: IsUnimplemented,
code: connect.CodeUnimplemented,
},
} {
tests := []struct {
name string
Expand Down
Loading