slogerr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

README

slogerr

Attach slog.Attr to an error and have them flatten across the wrap chain.

import "github.com/flamingoosesoftwareinc/slogerr"

err := slogerr.New(err, slog.String("resource", "visitor"))
err = slogerr.New(err, slog.String("id", "abc123"))

slog.Error("op failed", "err", err)
// level=ERROR msg="op failed" err.resource=visitor err.id=abc123

AnnotatedError implements error, Unwrap, and slog.LogValuer, so a handler renders the accumulated attributes as a group without any call-site plumbing. Attributes are collected from every AnnotatedError in the chain, outermost first.

func (e *AnnotatedError) Error() string
func (e *AnnotatedError) Unwrap() error
func (e *AnnotatedError) Attrs() []slog.Attr
func (e *AnnotatedError) LogValue() slog.Value

License

MPL-2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnotatedError

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

func New

func New(err error, attrs ...slog.Attr) *AnnotatedError

func (*AnnotatedError) Attrs

func (e *AnnotatedError) Attrs() []slog.Attr

func (*AnnotatedError) Error

func (e *AnnotatedError) Error() string

func (*AnnotatedError) LogValue

func (e *AnnotatedError) LogValue() slog.Value

func (*AnnotatedError) Unwrap

func (e *AnnotatedError) Unwrap() error

Jump to

Keyboard shortcuts

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