errs-go

module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0

README

errs-go

Extendable typed error handling for Go, with tags and optional stack frames.

Install

go get github.com/bronlabs/errs-go/errs

Quick start

package main

import (
	"fmt"

	"github.com/bronlabs/errs-go/errs"
)

var ValidationErr = errs.New("validation failed")

func main() {
	err := ValidationErr.
		WithTag("field", "email").
		WithMessage("missing @")
	
	fmt.Printf("%s", err)
}

Wrapping and joining

var (
    IOErr = errs.New("io error")
    UnsupportedErr = errs.New("unsupported operation")
)

func load() error {
	return IOErr.
		WithTag("path", "/tmp/input.txt").
		WithStackFrame()
}

func parse() error {
	return errs.Wrap(load()).
		WithMessage("parse error")
}

func main() {
	err := errs.Join(parse(), UnsupportedErr)
	if v, ok := errs.HasTag(err, "path"); ok {
		fmt.Println("path:", v)
	}
}

Utility helpers

The Must, Must1, and Must2 helpers are intended for setup and tests where failing fast is acceptable, such as parsing configuration, loading fixtures, or wiring dependencies. They let you keep call sites compact while still surfacing unexpected errors immediately.

value := errs.Must1(os.ReadFile("config.json"))

Compatibility

errs.Is and errs.As are aliases for errors.Is and errors.As, so you can use the standard library patterns across error chains produced by this library.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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