-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1512 from josephschorr/cursor-errors
Have invalid cursors return a proper error
- Loading branch information
Showing
3 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cursor | ||
|
||
import ( | ||
"errors" | ||
|
||
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/authzed/spicedb/pkg/spiceerrors" | ||
) | ||
|
||
// Public facing errors | ||
const ( | ||
errEncodeError = "error encoding cursor: %w" | ||
errDecodeError = "error decoding cursor: %w" | ||
) | ||
|
||
// ErrNilCursor is returned as the base error when nil is provided as the | ||
// cursor argument to Decode | ||
var ErrNilCursor = errors.New("cursor pointer was nil") | ||
|
||
// ErrHashMismatch is returned as the base error when a mismatching hash was given to the decoder. | ||
var ErrHashMismatch = errors.New("the cursor provided does not have the same arguments as the original API call; please ensure you are making the same API call, with the exact same parameters (besides the cursor)") | ||
|
||
// ErrInvalidCursor occurs when a cursor could not be decoded. | ||
type ErrInvalidCursor struct { | ||
error | ||
} | ||
|
||
// GRPCStatus implements retrieving the gRPC status for the error. | ||
func (err ErrInvalidCursor) GRPCStatus() *status.Status { | ||
return spiceerrors.WithCodeAndDetails( | ||
err, | ||
codes.InvalidArgument, | ||
spiceerrors.ForReason( | ||
v1.ErrorReason_ERROR_REASON_INVALID_CURSOR, | ||
nil, | ||
), | ||
) | ||
} | ||
|
||
// NewInvalidCursorErr creates and returns a new invalid cursor error. | ||
func NewInvalidCursorErr(err error) error { | ||
return ErrInvalidCursor{err} | ||
} |