warnx

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 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 warnx builds report warnings from errors as {code, location, detail_code}, so foreign error text never reaches warnings, logs or MCP output. It is the only package allowed to read error text.

Index

Constants

View Source
const (
	// DetailDeadlineExceeded: a deadline or network timeout expired.
	DetailDeadlineExceeded = "deadline_exceeded"
	// DetailCanceled: the operation was canceled.
	DetailCanceled = "canceled"
	// DetailNotFound: a file or object does not exist.
	DetailNotFound = "not_found"
	// DetailPermissionDenied: access was refused.
	DetailPermissionDenied = "permission_denied"
	// DetailNetworkError: a network or URL operation failed.
	DetailNetworkError = "network_error"
	// DetailParseError: JSON or number syntax was invalid.
	DetailParseError = "parse_error"
	// DetailUnclassified: no other detail code applies.
	DetailUnclassified = "unclassified"
)

Detail codes. A detail code says why, in a fixed vocabulary, so no error text is needed.

Variables

This section is empty.

Functions

func From

func From(err error) model.Warning

From turns err into a Warning without reading any error text. A warnx error found anywhere in the chain gives its code and location; else an error with a WarningCode() method that returns a documented code gives that code; any other error gives internal_error with no location. Unknown codes become internal_error. From(nil) is the zero Warning.

func New

func New(code, location string, err error) error

New returns an error that From turns into a Warning with code and location. The detail code is classified from err. Location is sanitised: URLs lose userinfo, query and fragment.

func WithDetail

func WithDetail(code, location, detailCode string, err error) error

WithDetail is New with an explicit detail code, which must match ^[a-z][a-z0-9_]*$; otherwise the detail is classified from err.

Types

type Error

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

Error is an error that already knows its warning. Wrap it further with %w as needed; From finds it with errors.As. Its text holds only the code and location.

func (*Error) Error

func (e *Error) Error() string

Error returns the code and location only, never the wrapped error's text.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error.

Jump to

Keyboard shortcuts

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