typederrors

package
v0.0.0-...-57fbcf5 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

Typed Errors

The errors defined in typed_errors.go provide new types for a more granular error management so the business logic can address specific errors if they are defined using those types.

Design

The error types defined embed a common error structure, GenericError type which :

  1. Implements the error interface, Error()
  2. Implements the unwrap method, Unwrap(), allowing to preserve and recover the original error. The new typed errors can therefore be part of an error chain.

The specific error type can be checked using the corresponding Is() function which uses errors.As() to identify the error type in an error chain.

Extension

New errors can be created just implementing:

  1. A new structure for the error, embedding GenericError, ie: TokenError
  2. A builder function (New) to return the previous type, through an error interface, ie: NewTokenError
  3. An Is function to check if the corresponding type is present in an error/error chain, ie: IsTokenError

Unit test

These errors and combinations of them exemplifying usages are tested in typed_errors_test.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConfigMapError

func IsConfigMapError(target error) bool

func IsNonRetriableError

func IsNonRetriableError(target error) bool

func IsRetriableError

func IsRetriableError(target error) bool

func IsSecretError

func IsSecretError(target error) bool

func IsTokenError

func IsTokenError(target error) bool

func NewConfigMapError

func NewConfigMapError(m string, e error) error

func NewNonRetriableError

func NewNonRetriableError(m string, e error) error

func NewRetriableError

func NewRetriableError(m string, e error) error

func NewSecretError

func NewSecretError(m string, e error) error

func NewTokenError

func NewTokenError(m string, e error) error

Types

type ConfigMapError

type ConfigMapError struct {
	GenericError
}

ConfigMapError type

type GenericError

type GenericError struct {
	Message string
	Err     error
}

GenericError is an error structure containing common fields to be embedded by specific error types defined below

func (GenericError) Error

func (ge GenericError) Error() string

func (GenericError) Unwrap

func (ge GenericError) Unwrap() error

type NonRetriableError

type NonRetriableError struct {
	GenericError
}

NonRetriableError type

type RetriableError

type RetriableError struct {
	GenericError
}

RetriableError type

type SecretError

type SecretError struct {
	GenericError
}

SecretError type

type TokenError

type TokenError struct {
	GenericError
}

TokenError type

Jump to

Keyboard shortcuts

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