errors

package module
v1.0.0 Latest Latest
Warning

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

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

README

Build Status Go Report Card Documentation Gocover

Errors

Simple error package for Go with minimal allocation and high performance. Optimized to keep error on function stack.

Motivation

I found out that the available error packages too complex for the simple purpose or not achieve the simple goal.

Purpose & Goal

Maintain an error chain (some kind of list of errors), and let the system to check whether the error's type caused the actual error or not.

Usage
package main

import (
    stderrors "errors"

    "github.com/PumpkinSeed/errors"
)

var ErrGlobal = errors.New("global err")
var ErrGlobal2 = errors.New("global err 2")
var ErrNotUsed = errors.New("not used err")

func main() {
    err := f3()
    
    stderrors.Is(err, ErrGlobal) // true
    stderrors.Is(err, ErrGlobal2) // true
    stderrors.Is(err, ErrNotUsed) // false

    println(err.Error()) // "global err 2: global err: string1"
}

func f1() error {
    return errors.New("string1")
}

func f2() error {
    return errors.Wrap(f1(), ErrGlobal)
}

func f3() error {
    return errors.Wrap(f2(), ErrGlobal2)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(text string) error

New creates a new error by using the genesis error

func Wrap

func Wrap(original error, wrapped error) error

Wrap new error into an existing error

Types

This section is empty.

Jump to

Keyboard shortcuts

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