errlay

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package errlay wraps errors with layer and code metadata and supports field filters through errors.Is and metadata extraction through errors.As.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(layer string, code uint8, msg string, err error) error

New creates a layered error wrapping err. A nil cause creates a leaf error.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/cohesian-tools/typy/errlay"
)

func main() {
	cause := errors.New("connection refused")
	err := errlay.New("database", 10, "query failed", cause)
	fmt.Println(err)
	fmt.Println(errors.Is(err, cause))
}
Output:
|layer database - 10| query failed connection refused
true

func Target

func Target(layer *string, code *uint8) error

Target returns a field filter for errors.Is. Nil fields are wildcards; two nil fields match any *Error. Both specified fields must match the same error in the chain. Target retains the supplied pointers.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/cohesian-tools/typy/errlay"
	"github.com/cohesian-tools/typy/ptr"
)

func main() {
	err := errlay.New("service", 1, "request failed",
		errlay.New("database", 10, "query failed", nil),
	)
	target := errlay.Target(ptr.New("database"), ptr.New(uint8(10)))
	fmt.Println(errors.Is(err, target))
	fmt.Println(errors.Is(err, errlay.Target(nil, nil)))
	fmt.Println(errors.Is(errors.New("ordinary error"), errlay.Target(nil, nil)))
}
Output:
true
true
false

Types

type Error

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

Error associates a layer, code, and message with an optional underlying cause.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/cohesian-tools/typy/errlay"
)

func main() {
	err := fmt.Errorf("context: %w", errlay.New("database", 10, "query failed", nil))
	var detail *errlay.Error
	if errors.As(err, &detail) {
		fmt.Println(detail.Layer(), detail.Code(), detail.Message())
	}
}
Output:
database 10 query failed

func (*Error) Code

func (e *Error) Code() uint8

Code returns the numeric code associated with the error.

func (*Error) Error

func (e *Error) Error() string

Error formats the metadata and appends the underlying cause when present.

func (*Error) Is

func (e *Error) Is(target error) bool
Is Chain

Is reports whether this error matches a filter constructed by Target. Use errors.Is to search the full error chain.

func (*Error) Layer

func (e *Error) Layer() string
Expose Methods

Layer returns the logical layer associated with the error.

func (*Error) Message

func (e *Error) Message() string

Message returns the local message without the metadata or underlying cause.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying cause for standard error-chain traversal.

Jump to

Keyboard shortcuts

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