Documentation
¶
Overview ¶
Package error defines some non-standard error mechanisms.
Deprecated: see individual entities for what to use instead.
Example (StringArray) ¶
details := make([]string, 3) details[0] = "alpha" details[1] = "bravo" details[2] = "charlie" err := NewErrorWithStringArray("message", details) wrapped := fmt.Errorf("Error: %w", err) dummy := NewErrorWithStringArrayDummy() if errors.As(wrapped, &dummy) { details := "" if withDetails, ok := err.(WithDetailArray); ok { for _, det := range withDetails.DetailStringArray() { if len(details) > 0 { details += ", " } details += det } } fmt.Printf("%s\nDetails: %s\n", wrapped, details) }
Output: Error: message Details: alpha, bravo, charlie
Example (StringMap) ¶
details := make(map[string]string, 3) details["alpha"] = "detail1" details["bravo"] = "detail two" details["charlie"] = "detail the third" err := NewErrorWithStringMap("message", details) wrapped := fmt.Errorf("error: %w", err) fmt.Printf("%s\n", wrapped) dummy := NewErrorWithStringMapDummy() if errors.As(wrapped, &dummy) { if withDetails, ok := err.(WithDetailMap); ok { detailed := withDetails.DetailStringMap() keyLen := 0 // Maps return keys/values in a deliberately random order, // so we must get the keys, sort them, and then use them. keys := make([]string, 0, len(detailed)) for k := range detailed { keys = append(keys, k) if len(k) > keyLen { keyLen = len(k) } } sort.Strings(keys) for _, key := range keys { fmt.Printf(" %*s: %s\n", keyLen, key, detailed[key]) } } }
Output: error: message alpha: detail1 bravo: detail two charlie: detail the third
Index ¶
- func Deprecated(name string) errordeprecated
- func NotYetImplemented() errordeprecated
- func ToBeImplemented(name string) errordeprecated
- type ErrorWithDetailArraydeprecated
- type ErrorWithDetailMapdeprecated
- type WithDetailArraydeprecated
- type WithDetailMapdeprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deprecated
deprecated
added in
v1.27.0
func NotYetImplemented
deprecated
added in
v1.26.0
func NotYetImplemented() error
NotYetImplemented returns a generic TBD error.
Deprecated: use struct msg.ErrNotImplemented.
func ToBeImplemented
deprecated
added in
v1.26.0
Types ¶
type ErrorWithDetailArray
deprecated
added in
v1.24.0
type ErrorWithDetailMap
deprecated
added in
v1.24.0
type WithDetailArray
deprecated
added in
v1.26.0
WithDetailArray interface provides a way to determine if an error has string details.
Deprecated: Use Go package errors.Join() instead.
func NewErrorWithStringArray
deprecated
func NewErrorWithStringArray(msg string, detail []string) WithDetailArray
NewErrorWithStringArray constructs an error with an array of string details.
Deprecated: Use Go package errors.Join() instead.
func NewErrorWithStringArrayDummy
deprecated
added in
v1.20.0
func NewErrorWithStringArrayDummy() WithDetailArray
NewErrorWithStringArrayDummy provides an empty error object for use with errors.As()
Deprecated: Use Go package errors.Join() instead.
type WithDetailMap
deprecated
added in
v1.26.0
WithDetailMap interface provides a way to determine if an error has string details.
Deprecated: No obvious replacement.
func NewErrorWithStringMap
deprecated
func NewErrorWithStringMap(msg string, detail map[string]string) WithDetailMap
NewErrorWithStringMap constructs an error with a map of strings representing error details.
Deprecated: No obvious replacement.
func NewErrorWithStringMapDummy
deprecated
added in
v1.20.0
func NewErrorWithStringMapDummy() WithDetailMap
NewErrorWithStringMapDummy provides an empty error object for use with errors.As()
Deprecated: No obvious replacement.