cerrors

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cerrors contains functions related to error handling.

The standard library's errors package is missing some functionality which we need, such as stack traces. To be certain that all errors created in Conduit are created with the additional information, usage of this package is mandatory.

At present, the package acts as a "thin forwarding layer", where we "mix and match" functions from different packages.

Package cerrors contains functions related to error handling.

The standard library's errors package is missing some functionality which we need, such as stack traces. To be certain that all errors created in Conduit are created with the additional information, usage of this package is mandatory.

At present, the package acts as a "thin forwarding layer", where we "mix and match" functions from different packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	// xerrors is used, since it provides the stack traces too
	New    = xerrors.New    //nolint:forbidigo // xerrors.New is allowed here, but not anywhere else
	Errorf = xerrors.Errorf //nolint:forbidigo // xerrors.Errorf is allowed here, but not anywhere else
	Is     = errors.Is
	As     = errors.As
	Unwrap = errors.Unwrap
	Join   = errors.Join
)
View Source
var (
	// ErrNotImpl should be used when a functionality which is not yet implemented was called.
	ErrNotImpl = New("not impl")
	// ErrEmptyID should be used when an entity was requested, but the ID was not provided.
	ErrEmptyID = New("empty ID")
)

Functions

func GetStackTrace

func GetStackTrace(err error) interface{}

func LogOrReplace added in v0.3.0

func LogOrReplace(oldErr, newErr error, log func()) error

LogOrReplace is a utility meant to be called in deferred functions that can produce an error. In that case we have two options:

  1. Group errors together (e.g. with the multierror package).
  2. Use LogOrReplace to either log the error or return it.

The second option is preferable when the original error returning from the function is more important than the deferred error. LogOrReplace will return the original error if it is not nil, otherwise it will return the new error. If both errors are not nil, then the log function will be called, that can be used to log the new error.

Example how it's supposed to be used:

func() (err error) {
  defer func() {
    cleanupErr := cleanup()
    err = cerrors.LogOrReplace(err, cleanupErr, func() {
      fmt.Printf("cleanup error: %v", cleanupErr)
    })
  }
  // execute logic that can produce an error
  return err
}

Types

type Frame

type Frame struct {
	Func string `json:"func,omitempty"`
	File string `json:"file,omitempty"`
	Line int    `json:"line,omitempty"`
}

Jump to

Keyboard shortcuts

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