errclass

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Overview

Package errclass implements error classification.

The general idea is to classify golang errors to an enum of strings with names resembling standard Unix error names.

Design Principles

1. Preserve original error in `err` in the structured logs.

2. Add the classified error as the `errClass` field.

3. Use errors.Is and errors.As for classification.

4. Use string-based classification for readability.

5. Follow Unix-like naming where appropriate.

6. Prefix subsystem-specific errors (`EDNS_`, `ETLS_`).

7. Keep full names for clarity over brevity.

8. Map the nil error to an empty string.

System and Network Errors

- ETIMEDOUT for context.DeadlineExceeded, os.ErrDeadlineExceeded

- EINTR for context.Canceled, net.ErrClosed

- EEOF for (unexpected) io.EOF and io.ErrUnexpectedEOF errors

- ECONNRESET, ECONNREFUSED, ... for respective syscall errors

The actual system error constants are defined in platform-specific files:

- unix.go for Unix-like systems using x/sys/unix

- windows.go for Windows systems using x/sys/windows

This ensures proper mapping between the standardized error classes and platform-specific error constants.

DNS Errors

- EDNS_NONAME for errors with the "no such host" suffix

- EDNS_NODATA for errors with the "no answer" suffix

TLS

- ETLS_HOSTNAME_MISMATCH for hostname verification failure

- ETLS_CA_UNKNOWN for unknown certificate authority

- ETLS_CERT_INVALID for invalid certificate

Fallback

- EGENERIC for unclassified errors

Index

Constants

View Source
const (

	// EADDRNOTAVAIL is the address not available error.
	EADDRNOTAVAIL = "EADDRNOTAVAIL"

	// EADDRINUSE is the address in use error.
	EADDRINUSE = "EADDRINUSE"

	// ECONNABORTED is the connection aborted error.
	ECONNABORTED = "ECONNABORTED"

	// ECONNREFUSED is the connection refused error.
	ECONNREFUSED = "ECONNREFUSED"

	// ECONNRESET is the connection reset by peer error.
	ECONNRESET = "ECONNRESET"

	// EHOSTUNREACH is the host unreachable error.
	EHOSTUNREACH = "EHOSTUNREACH"

	// EEOF indicates an unexpected EOF.
	EEOF = "EEOF"

	// EINVAL is the invalid argument error.
	EINVAL = "EINVAL"

	// EINTR is the interrupted system call error.
	EINTR = "EINTR"

	// ENETDOWN is the network is down error.
	ENETDOWN = "ENETDOWN"

	// ENETUNREACH is the network unreachable error.
	ENETUNREACH = "ENETUNREACH"

	// ENOBUFS is the no buffer space available error.
	ENOBUFS = "ENOBUFS"

	// ENOTCONN is the not connected error.
	ENOTCONN = "ENOTCONN"

	// EPROTONOSUPPORT is the protocol not supported error.
	EPROTONOSUPPORT = "EPROTONOSUPPORT"

	// ETIMEDOUT is the operation timed out error.
	ETIMEDOUT = "ETIMEDOUT"

	// EDNS_NONAME is the DNS error for "no such host".
	EDNS_NONAME = "EDNS_NONAME"

	// EDNS_NODATA 	is the DNS error for "no answer".
	EDNS_NODATA = "EDNS_NODATA"

	// ETLS_HOSTNAME_MISMATCH is the TLS error for hostname verification failure.
	ETLS_HOSTNAME_MISMATCH = "ETLS_HOSTNAME_MISMATCH"

	// ETLS_CA_UNKNOWN is the TLS error for unknown certificate authority.
	ETLS_CA_UNKNOWN = "ETLS_CA_UNKNOWN"

	// ETLS_CERT_INVALID is the TLS error for invalid certificate.
	ETLS_CERT_INVALID = "ETLS_CERT_INVALID"

	// EGENERIC is the generic, unclassified error.
	EGENERIC = "EGENERIC"
)

Variables

This section is empty.

Functions

func New

func New(err error) string

New creates a new error class from the given error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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