Skip to content

Commit

Permalink
GOCBC-1540: Update couchbase2 error handling to match RFC
Browse files Browse the repository at this point in the history
Motivation
----------
The couchbase2 error handling RFC has been updated.

Changes
-------
Add handling for missing preconditions.
Add ErrDocumentTooDeep and return accordingly.
Remove error handling for codes we no longer handle.

Change-Id: I7911f92bc8d649d4a8b32bc8800b03aa3ba21655
Reviewed-on: https://review.couchbase.org/c/gocb/+/200740
Tested-by: Charles Dixon <chvckd@gmail.com>
Reviewed-by: Dimitris Christodoulou <dimitris.christodoulou@couchbase.com>
  • Loading branch information
chvck committed Nov 15, 2023
1 parent da03d16 commit 21564db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 6 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,10 @@ var (
// ErrCircuitBreakerOpen occurs when the operation was cancelled because the circuit breaker was open
// # UNCOMMITTED: This API may change in the future.
ErrCircuitBreakerOpen = gocbcore.ErrCircuitBreakerOpen

// ErrDocumentTooDeep occurs when an operation would cause a document to be
// nested beyond the depth limits allowed by the sub-document specification.
// This error occurs when couchbase2 scheme is in use and is equivalent to
// ErrPathTooDeep when other schemes are used.
ErrDocumentTooDeep = errors.New("document too deep")
)
23 changes: 7 additions & 16 deletions error_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ const (
preconditionPathMismatch = "PATH_MISMATCH"
preconditionDocNotJSON = "DOC_NOT_JSON"
preconditionDocTooDeep = "DOC_TOO_DEEP"
preconditionWouldInvalidateJSON = "WOULD_INVALIDATE_JSON"
preconditionValueTooLarge = "VALUE_TOO_LARGE"
// Not currently used as it's unclear what exception this maps to.
// preconditionPathValueOutOfRange = "PATH_VALUE_OUT_OF_RANGE"
preconditionValueOutOfRange = "VALUE_OUT_OF_RANGE"
preconditionPathValueOutOfRange = "PATH_VALUE_OUT_OF_RANGE"
)

const (
Expand Down Expand Up @@ -65,11 +64,13 @@ func mapPsErrorStatusToGocbError(st *status.Status, readOnly bool) *GenericError
case preconditionDocNotJSON:
baseErr = ErrDocumentNotJSON
case preconditionDocTooDeep:
baseErr = ErrValueTooDeep
case preconditionWouldInvalidateJSON:
baseErr = ErrValueInvalid
baseErr = ErrDocumentTooDeep
case preconditionValueTooLarge:
baseErr = ErrValueTooLarge
case preconditionValueOutOfRange:
baseErr = ErrValueInvalid
case preconditionPathValueOutOfRange:
baseErr = ErrNumberTooBig
}
}
case *errdetails.ResourceInfo:
Expand Down Expand Up @@ -129,14 +130,8 @@ func mapPsErrorStatusToGocbError(st *status.Status, readOnly bool) *GenericError
switch st.Code() {
case codes.Canceled:
baseErr = ErrRequestCanceled
case codes.Aborted:
baseErr = ErrInternalServerFailure
case codes.Unknown:
baseErr = ErrInternalServerFailure
case codes.Internal:
baseErr = ErrInternalServerFailure
case codes.OutOfRange:
baseErr = ErrInvalidArgument
case codes.InvalidArgument:
baseErr = ErrInvalidArgument
case codes.DeadlineExceeded:
Expand All @@ -145,10 +140,6 @@ func mapPsErrorStatusToGocbError(st *status.Status, readOnly bool) *GenericError
} else {
baseErr = ErrAmbiguousTimeout
}
case codes.NotFound:
baseErr = ErrDocumentNotFound
case codes.AlreadyExists:
baseErr = ErrDocumentExists
case codes.Unauthenticated:
baseErr = wrapError(ErrAuthenticationFailure, "server reported that permission to the resource was denied")
case codes.PermissionDenied:
Expand Down

0 comments on commit 21564db

Please sign in to comment.