errorstest

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errorstest provides test assertions on the error code a pkg/errors chain reports.

Consumers such as errors.ExitCodeFromError read the code of the outermost *errors.StructuredError. errors.Is matches a code anywhere in the chain, so an assertion built on it still passes when the expected code is buried under a wrap that reports a different one. Use these helpers to assert what a consumer reads. Keep errors.Is for asserting that a code is absent, where matching anywhere in the chain is the stricter check.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportedCode

func ReportedCode(err error) errors.ErrorCode

ReportedCode returns the Code of the outermost *errors.StructuredError in err's Unwrap chain, or the empty code when the chain has none. It sees through non-structured wraps such as fmt.Errorf("%w", ...).

func WantReportedCode

func WantReportedCode(t testing.TB, err error, code errors.ErrorCode)

WantReportedCode fails t unless err reports code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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