failure

package module
v0.0.0-...-92d1fe9 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 3 Imported by: 5

README

GoDoc Go Report Card CI

failure


Copyright (c) 2020 Institut National de l'Audiovisuel

Documentation

Overview

Package failure allows to add context, debugging information to errors.

So instead of the traditional:

if err != nil {
    return err
}

it can be interesting to generate a new error including the initial error while giving it some context:

if err := task.Execute(); err != nil {
    return failure.New(err).Set("task", task.ID()).Msg("impossible to perform this task")
}

It is of course possible to generate completely new errors :

if got != want {
    return failure.New(nil).
        Set("got", got).
        Set("want", want).
        Msg("the value received is not the right one")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failure

type Failure struct {
	// contains filtered or unexported fields
}

Failure AFAIRE.

func New

func New(err error) *Failure

New AFAIRE.

func Unexpected

func Unexpected() *Failure

Unexpected AFAIRE.

func (*Failure) Error

func (f *Failure) Error() string

Error AFAIRE.

func (*Failure) Msg

func (f *Failure) Msg(msg string) *Failure

Msg AFAIRE.

func (*Failure) Msgf

func (f *Failure) Msgf(format string, args ...interface{}) *Failure

Msgf AFAIRE.

func (*Failure) Set

func (f *Failure) Set(key string, value interface{}) *Failure

Set AFAIRE.

func (*Failure) Setf

func (f *Failure) Setf(key, format string, args ...interface{}) *Failure

Setf AFAIRE.

func (*Failure) Unwrap

func (f *Failure) Unwrap() error

Unwrap AFAIRE.

Jump to

Keyboard shortcuts

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