You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change equips the error library with string redaction according
to the algorithms and ideas from github.com/cockroachdb/redact.
It is backward incompatible in two ways:
- it breaks support with Go 1.12. The code is now 1.13+ only.
- the `errors.Safe()` function has a new return type.
New:
- When an error object is passed as formatting argument to `Newf()`,
`Wrapf()` and similar (i.e. not as first argument in `Wrap`),
it is now attached as secondary payload as per
`errors.WithSecondaryError()`.
This ensures that more details about these errors are included
eventually in Sentry reports.
- The full text of the error message, with sensitive bits redacted
out, is now included at the head of Sentry reports.
- The new `errors.SafeFormatter` interface mimics `errors.Formatter`,
with a method `SafeFormatError()`. Its `Printer` argument has
`Print()` methods that behave like `redact.SafeWriter`: they
distinguish sensitive and non-sensitive error bits.
For example:
```go
func (myError) SafeFormatError(p errors.Printer) {
p.Printf("hello %s", "world")
// ^^^^^ safe
// ^^^^^^^ unsafe
p.Printf("hello %s", errors.Safe("world"))
// ^^^^^ safe
// ^^^^^^^^^^^^^^^^^^^^^ safe
}
```
This method can be implemented *instead of* `FormatError()`; the
error library will know how to use it if present.
- The new `errors.Formattable()` wrapper transforms any `error`
instance into a `fmt.Formatter` which will detail the error
adequately, even if the error type does not implement `FormatError`.
Example use:
```go
fmt.Printf("hello: %v", errors.Formattable(err))
```
API changes:
- `errors.Formatter` continues to be supported for compatibility
with Go 1.13's `xerror` proposal. It is however deprecated
in favor of `errors.SafeFormatter`.
- `errors.Safe()` is now an alias for `redact.Safe()`. It now returns
a `redact.SafeValue` instead of a `SafeMessager`.
- The `errors.SafeMessager` interface is deprecated. Use
the `redact.SafeFormatter` interface, or the other
APIs from the `redact` package.
- The "complex" constructors `errors.New*()`, `errors.Wrap*()` now use
facilities from the `redact` package to distinguish safe and unsafe
arguments, instead of the `WithSafeDetails()` wrapper. This makes
the chain of errors simpler.
- **when to use: need to embark a message string to output when the error is presented to a human.**
208
209
- what it does: captures detail strings.
209
-
- how to access the detail: `errors.GetAllDetails()`, `errors.FlattenDetails()` (all details are preserved), format with `%+v`.
210
+
- how to access the detail: `errors.GetAllDetails()`, `errors.FlattenDetails()` (all details are preserved), format with `%+v`.Not included in Sentry reports.
210
211
211
212
- `WithHint(error, string) error`, `WithHintf(error, string, ...interface{}) error`: user-facing detail with suggestion for action to take.
212
213
- **when to use: need to embark a message string to output when the error is presented to a human.**
213
214
- what it does: captures hint strings.
214
-
- how to access the detail: `errors.GetAllHints()`, `errors.FlattenHints()` (hints are de-duplicated), format with `%+v`.
215
+
- how to access the detail: `errors.GetAllHints()`, `errors.FlattenHints()` (hints are de-duplicated), format with `%+v`.Not included in Sentry reports.
215
216
216
217
- `WithIssueLink(error, IssueLink) error`: annotate an error with an URL and arbitrary string.
217
218
- **when to use: to refer (human) users to some external resources.**
@@ -260,7 +261,7 @@ considered to be PII-free, and thus included in Sentry reports automatically:
260
261
- the `format string` argument of `Newf`, `AssertionFailedf`, etc (the constructors ending with `...f()`),
261
262
- the *type* of the additional arguments passed to the `...f()` constructors,
262
263
- the *value of specific argument types* passed to the `...f()` constructors, when known to be PII-safe.
263
-
For details of which arguments are considered PII-free, see the [`Redact()` function](safedetails/redact.go).
264
+
For details of which arguments are considered PII-free, see the [`redact`package](https://github.com/cockroachdb/redact).
264
265
265
266
It is possible to opt additional in to Sentry reporting, using either of the following methods:
266
267
@@ -293,7 +294,7 @@ If your error type is a wrapper, you should implement a `Format()`
293
294
method that redirects to `errors.FormatError()`, otherwise `%+v` will
294
295
not work. Additionally, if your type has a payload not otherwise
295
296
visible via `Error()`, you may want to implement
296
-
`errors.Formatter`. See [making `%+v` work with your
297
+
`errors.SafeFormatter`. See [making `%+v` work with your
297
298
type](#Making-v-work-with-your-type) below for details.
298
299
299
300
Finally, you may want your new errortype to be portable across
@@ -445,8 +446,8 @@ In short:
445
446
type, this will disable the recursive application of the `%+v` flag
446
447
to the causes chained from your wrapper.)
447
448
448
-
- You may optionally implement the `errors.Formatter` interface:
449
-
`FormatError(p errors.Printer) (next error)`. This is optional, but
449
+
- You may optionally implement the `errors.SafeFormatter` interface:
450
+
`SafeFormatError(p errors.Printer) (next error)`. This is optional, but
450
451
should be done when some details are not included by `Error()` and
0 commit comments