MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / connectToBucketErrorHandling

Function connectToBucketErrorHandling

db/database.go:316–337  ·  view source on GitHub ↗

connectToBucketErrorHandling takes the given spec and error and returns a formatted error, along with whether it was a fatal error.

(ctx context.Context, spec base.BucketSpec, gotErr error)

Source from the content-addressed store, hash-verified

314
315// connectToBucketErrorHandling takes the given spec and error and returns a formatted error, along with whether it was a fatal error.
316func connectToBucketErrorHandling(ctx context.Context, spec base.BucketSpec, gotErr error) (fatalError bool, err error) {
317 if gotErr != nil {
318 if errors.Is(gotErr, base.ErrAuthError) {
319 username, _, _ := spec.Auth.GetCredentials()
320 base.WarnfCtx(ctx, "Unable to authenticate as user %q: %v", base.UD(username), gotErr)
321 // auth errors will be wrapped with HTTPError further up the stack where appropriate. Return the raw error that can still be checked.
322 return false, gotErr
323 }
324
325 // Fatal errors get an additional log message, but are otherwise still transformed below.
326 if errors.Is(gotErr, base.ErrFatalBucketConnection) {
327 base.WarnfCtx(ctx, "Fatal error connecting to bucket: %v", gotErr)
328 fatalError = true
329 }
330
331 // Remaining errors are appended to the end of a more helpful error message.
332 return fatalError, base.HTTPErrorf(http.StatusBadGateway,
333 " Unable to connect to Couchbase Server (connection refused). Please ensure it is running and reachable at the configured host and port. Detailed error: %s", gotErr)
334 }
335
336 return false, nil
337}
338
339type OpenBucketFn func(context.Context, base.BucketSpec, bool) (base.Bucket, error)
340

Callers 1

ConnectToBucketFunction · 0.85

Calls 4

WarnfCtxFunction · 0.92
UDFunction · 0.92
HTTPErrorfFunction · 0.92
GetCredentialsMethod · 0.65

Tested by

no test coverage detected