errorwrapper-go

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT

README

errorwrapper-go

Go Reference Go Report Card

A tiny Go library for building structured, prefix-chained error messages.


Install

go get -u github.com/colduction/errorwrapper-go/v1

Usage

import errorwrapper "github.com/colduction/errorwrapper-go/v1"

e1 := errorwrapper.New('.', "database")
err1 := e1.NewErrorString("connection refused")
// → "database: connection refused"

e2 := errorwrapper.New('.', "repository")
err2 := e2.NewError(err1)
// → "repository.database: connection refused"

e3 := errorwrapper.New('.', "service")
err3 := e3.NewError(err2, "query failed")
// → "service.repository.database: [query failed] connection refused"

API

Function Description
New(joiner byte, prefix ...string) ErrorWrapper Creates a new wrapper with an optional prefix and joiner (default .)
(ew) NewError(err error, msg ...string) error Wraps an existing error, merging any prefix chain
(ew) NewErrorString(errStr string, msg ...string) error Creates and wraps a new error from a string
  • Returns nil when given a nil error or an empty string.
  • Prefix chains are flattened automatically when wrappers are nested.

License

This project is licensed under the terms of the MIT License.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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