error

package
v1.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 1 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deprecated deprecated added in v1.27.0

func Deprecated(name string) error

Deprecated returns a deprecation error specifying the name of the deprecated function or method.

Deprecated: use struct msg.ErrDeprecated.

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

func ToBeImplemented(name string) error

ToBeImplemented returns a TBD error specifying the name of the unimplemented function or method.

Deprecated: use struct msg.ErrNotImplemented.

Types

type ErrorWithDetailArray deprecated added in v1.24.0

type ErrorWithDetailArray interface {
	error
	DetailStringArray() []string
}

ErrorWithDetailArray interface provides a way to determine if an error has string details.

Deprecated: Name begins with package name, use error.WithDetailArray instead.

type ErrorWithDetailMap deprecated added in v1.24.0

type ErrorWithDetailMap interface {
	error
	DetailStringMap() map[string]string
}

ErrorWithDetailMap interface provides a way to determine if an error has string details.

Deprecated: No obvious replacement.

type WithDetailArray deprecated added in v1.26.0

type WithDetailArray interface {
	error
	DetailStringArray() []string
}

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

type WithDetailMap interface {
	error
	DetailStringMap() map[string]string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL