Commit ce5f4db
authored
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.1 parent 797a9bd commit ce5f4db
2 files changed
+42
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
| 49 | + | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
50 | 52 | | |
51 | | - | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
85 | | - | |
| 91 | + | |
86 | 92 | | |
87 | 93 | | |
88 | 94 | | |
| |||
0 commit comments