Skip to content

Document intended differences between WithHint and WithDetail (#114) #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ return errors.Wrap(foo(), "foo")
- how to access the detail: `Error()`, regular Go formatting, Sentry Report.

- `WithDetail(error, string) error`, `WithDetailf(error, string, ...interface{}) error`, user-facing detail with contextual information.
- **when to use: need to embark a message string to output when the error is presented to a human.**
- **when to use: need to embark a message string to output when the error is presented to a developer.**
- what it does: captures detail strings.
- how to access the detail: `errors.GetAllDetails()`, `errors.FlattenDetails()` (all details are preserved), format with `%+v`. Not included in Sentry reports.

- `WithHint(error, string) error`, `WithHintf(error, string, ...interface{}) error`: user-facing detail with suggestion for action to take.
- **when to use: need to embark a message string to output when the error is presented to a human.**
- **when to use: need to embark a message string to output when the error is presented to an end user.**
- what it does: captures hint strings.
- how to access the detail: `errors.GetAllHints()`, `errors.FlattenHints()` (hints are de-duplicated), format with `%+v`. Not included in Sentry reports.

Expand Down
5 changes: 4 additions & 1 deletion hintdetail/hintdetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

// WithHint decorates an error with a textual hint.
// The hint may contain PII and thus will not reportable.
// The suggested use case for hint is to relay information to end users.
//
// Hint is shown:
// - when formatting with `%+v`.
Expand Down Expand Up @@ -97,10 +98,12 @@ type ErrorHinter interface {

// WithDetail decorates an error with a textual detail.
// The detail may contain PII and thus will not reportable.
// The suggested use case for detail is to augment errors with information
// useful for debugging.
//
// Detail is shown:
// - when formatting with `%+v`.
// - with `GetAllHints()` / `FlattenHints()` below.
// - with `GetAllDetails()` / `FlattenDetails()` below.
//
// Note: the detail does not appear in the main error message returned
// with Error(). Use GetAllDetails() or FlattenDetails() to retrieve
Expand Down
5 changes: 4 additions & 1 deletion hintdetail_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ErrorDetailer = hintdetail.ErrorDetailer

// WithHint decorates an error with a textual hint.
// The hint may contain PII and thus will not reportable.
// The suggested use case for hint is to relay information to end users.
//
// Hint is shown:
// - when formatting with `%+v`.
Expand All @@ -44,10 +45,12 @@ func WithHintf(err error, format string, args ...interface{}) error {

// WithDetail decorates an error with a textual detail.
// The detail may contain PII and thus will not reportable.
// The suggested use case for detail is to augment errors with information
// useful for debugging.
//
// Detail is shown:
// - when formatting with `%+v`.
// - with `GetAllHints()` / `FlattenHints()` below.
// - with `GetAllDetails()` / `FlattenDetails()` below.
//
// Note: the detail does not appear in the main error message returned
// with Error(). Use GetAllDetails() or FlattenDetails() to retrieve
Expand Down