| 28 | } |
| 29 | |
| 30 | func ExampleErrorf() { |
| 31 | // Errors created with Errorf are redacted by omitting any arguments not |
| 32 | // marked as safe. The literal portion of the format string is kept. |
| 33 | wrapped := errors.New("not found") |
| 34 | name := "Alex" |
| 35 | id := 5 |
| 36 | err := Errorf("error getting user %s with ID %d: %w", name, Safe(id), wrapped) |
| 37 | |
| 38 | fmt.Println("Normal:", err) |
| 39 | fmt.Println("Redacted:", Error(err)) |
| 40 | // Output: |
| 41 | // Normal: error getting user Alex with ID 5: not found |
| 42 | // Redacted: error getting user <redacted string> with ID 5: <redacted *errors.errorString> |
| 43 | } |
| 44 | |
| 45 | func ExampleError_wrapped() { |
| 46 | // If an error wraps another, then redacting it results in a message with the |