errstack

package module
v0.0.0-...-787d88d Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 5 Imported by: 0

README

errstack

Go Reference

A very small library to combine errors.

Furthermore, I want my errors to display the filename and line number.

pool.go:19="missing max value" users.go:25="missing password field"

Example

package main

import (
    "log"
)

func main() {
    // 1. Something bad happened at the beginning of your stack.
    e := errstack.New("password field is missing")

    // 2. And then the second error occured.
    e.Append("company name is missing")

    // 3. And then the third error occured.
    e.Append("username is too short")

    log.Println(e.Error())
    // The log will look like this:
    // /path/to/project.go:68="username is too short" /path/to/project.go:65="company name is missing" /path/to/project.go:15="password field is missing"
}

My other Go libraries

  • Tollbooth: A generic middleware to rate-limit HTTP requests.

  • Stopwatch: A small library to measure latency of things. Useful if you want to report latency data to Graphite.

  • LaborUnion: A dynamic worker pool library.

  • Gomet: Simple HTTP client & server long poll library for Go. Useful for receiving live updates without needing Websocket.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Err

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

Err struct contains filename, line number, and error message

func NewErr

func NewErr(err string) *Err

NewErr returns *Err struct

func (*Err) Error

func (e *Err) Error() string

Error satisfies the error interface

func (*Err) SetShowMetadata

func (e *Err) SetShowMetadata(showMetadata bool) *Err

SetShowMetadata is a flag to display/hide filename and line number

func (*Err) SetTrimFilename

func (e *Err) SetTrimFilename(trimFilename bool) *Err

SetTrimFilename is a flag to trim filename

type ErrStack

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

ErrStack contains the error stack

func New

func New(err string) *ErrStack

New creates a new ErrStack given an error string

func (*ErrStack) Append

func (es *ErrStack) Append(err string) *ErrStack

Append allows users to append an error string

func (*ErrStack) AppendErr

func (es *ErrStack) AppendErr(err *Err) *ErrStack

AppendErr allows users to append *Err struct into the stack

func (*ErrStack) Error

func (es *ErrStack) Error() string

Error satisfies the error interface

func (*ErrStack) GetAll

func (es *ErrStack) GetAll() []*Err

GetAll returns a list of *Err structs in a LIFO fashion

func (*ErrStack) PopAll

func (es *ErrStack) PopAll() []*Err

PopAll returns a list of *Err structs in a LIFO fashion and clears the stack.

func (*ErrStack) SetShowMetadata

func (es *ErrStack) SetShowMetadata(showMetadata bool) *ErrStack

SetShowMetadata is a flag to display/hide filename and line number

func (*ErrStack) SetTrimFilename

func (es *ErrStack) SetTrimFilename(trimFilename bool) *ErrStack

SetTrimFilename is a flag to trim filename

Jump to

Keyboard shortcuts

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