Documentation ¶
Overview ¶
Package errorstack exposes a set of utilities for consistent error handling in the helix ecosystem. Every package in helix.go relies on this one.
This package must not import any other package of this ecosystem.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { // Integration is the name of the integration returning the error, if applicable. // Omit integration when working with JSON: we don't want to give internal // information to clients consuming HTTP APIs. // // Examples: // // "nats" // "vault" Integration string `json:"-"` // Message is the top-level message of the error. Message string `json:"message,omitempty"` // Validations represents a list of failure validations related to the error // itself. This allows to pass/retrieve additional details, such as validation // failures encountered in the request payload. Validations []Validation `json:"validations,omitempty"` // Children holds child errors encountered in cascade related to the current // error. Omit children errors when working with JSON: we don't want to give // internal information to clients consuming HTTP APIs. Children []error `json:"-"` }
Error implements the Go native error type and is designed for handling errors in the helix ecosystem. When exposing errors to clients (such as via HTTP API), the root error should not give away too much information such as internal messages.
func NewFromError ¶
NewFromError returns a new error given the existing error and options passed.
func (*Error) Error ¶
Error returns the stringified version of the error, including its validation failures.
func (*Error) HasChildren ¶
HasChildren indicates if an error caused other (a.k.a. children) errors.
func (*Error) HasValidations ¶
HasValidations indicates if an error encountered validation failures.
func (*Error) WithChildren ¶
WithChildren adds a list of child errors encountered related to the current error.
func (*Error) WithValidations ¶
func (err *Error) WithValidations(validations ...Validation) *Error
WithValidations adds validation failures to an error.
type Validation ¶
type Validation struct { // Message is the cause of the validation failure. Message string `json:"message"` // Path represents the path to the key where the validation failure occurred. // // Example: // // []string{"request", "body", "user", "email"} Path []string `json:"path,omitempty"` }
Validation holds some details about a validation failure.