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 ¶
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 ¶
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 ¶
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 ¶
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.