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)
| 314 | |
| 315 | // connectToBucketErrorHandling takes the given spec and error and returns a formatted error, along with whether it was a fatal error. |
| 316 | func 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 | |
| 339 | type OpenBucketFn func(context.Context, base.BucketSpec, bool) (base.Bucket, error) |
| 340 |
no test coverage detected