| 43 | } |
| 44 | |
| 45 | func ExampleError_wrapped() { |
| 46 | // If an error wraps another, then redacting it results in a message with the |
| 47 | // redacted version of each error in the chain up until the first redactable |
| 48 | // error. |
| 49 | name := "Alex" |
| 50 | err := fmt.Errorf("fatal error: %w", |
| 51 | Errorf("error getting user %s: %w", name, |
| 52 | errors.New("not found"))) |
| 53 | |
| 54 | fmt.Println("Normal:", err) |
| 55 | fmt.Println("Redacted:", Error(err)) |
| 56 | // Output: |
| 57 | // Normal: fatal error: error getting user Alex: not found |
| 58 | // Redacted: <redacted *fmt.wrapError>: error getting user <redacted string>: <redacted *errors.errorString> |
| 59 | } |
| 60 | |
| 61 | func TestNil(t *testing.T) { |
| 62 | checkUnredactedError(t, nil, "<nil>") |