Help us shape the future of Go! Take the 2026 Go Developer Survey

slogerr

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 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 (
    "errors"
    "log/slog"

    "github.com/flamingoosesoftwareinc/slogerr"
)

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

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

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

The group's message field comes from Error(). Top-level annotations named message are omitted from log output; Attrs() still returns them unchanged. Use a named group for contextual message attributes, such as context.message.

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