Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(internal): provide wrapping for retried errors (#4797)
This modifies the retry code to allow both context and service errors to be available when the call was retried until hitting a context deadline or cancelation. This preserves the error string as it is currently put together by internal/annotate; for example a googleapi error from storage looks like this: `object.Attrs: retry failed with context deadline exceeded; last error: googleapi: got HTTP response code 503 with body: {"code":"503","message":{"error":{"message":"Retry Test: Caused a 503"}}}` Go 1.13 error semantics can be used to introspect the underlying context and service errors; here are some examples: ``` _, err = client.Bucket(bucketName).Object(objName).Attrs(timeoutCtx) if err != nil { if e, ok := err.(interface{ Unwrap() error }); ok { wrappedErr := e.Unwrap() // yields googleapi.Error type. } // errors.As allows unwrapping with access to googleapi.Error fields. var errAsGoogleapi *googleapi.Error if errors.As(err, &errAsGoogleapi) { log.Printf("error code: %v", errAsGoogleapi.Code) } isDeadlineExceeded := errors.Is(err, context.DeadlineExceeded) // true } ``` internal.Retry is used by the storage, datastore and bigquery clients, as well as integration tests for compute and pubsub. I want to make sure to check this with everyone affected.
- Loading branch information