github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/cursor/errors.go (about) 1 package cursor 2 3 import ( 4 "errors" 5 6 v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" 7 "google.golang.org/grpc/codes" 8 "google.golang.org/grpc/status" 9 10 "github.com/authzed/spicedb/pkg/spiceerrors" 11 ) 12 13 // Public facing errors 14 const ( 15 errEncodeError = "error encoding cursor: %w" 16 errDecodeError = "error decoding cursor: %w" 17 ) 18 19 // ErrNilCursor is returned as the base error when nil is provided as the 20 // cursor argument to Decode 21 var ErrNilCursor = errors.New("cursor pointer was nil") 22 23 // ErrHashMismatch is returned as the base error when a mismatching hash was given to the decoder. 24 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)") 25 26 // ErrInvalidCursor occurs when a cursor could not be decoded. 27 type ErrInvalidCursor struct { 28 error 29 } 30 31 // GRPCStatus implements retrieving the gRPC status for the error. 32 func (err ErrInvalidCursor) GRPCStatus() *status.Status { 33 return spiceerrors.WithCodeAndDetails( 34 err, 35 codes.InvalidArgument, 36 spiceerrors.ForReason( 37 v1.ErrorReason_ERROR_REASON_INVALID_CURSOR, 38 nil, 39 ), 40 ) 41 } 42 43 // NewInvalidCursorErr creates and returns a new invalid cursor error. 44 func NewInvalidCursorErr(err error) error { 45 return ErrInvalidCursor{err} 46 }