errors

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package errors defines some error types and provides functions to identify the type of specified error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As directly calls the github.com/donyori/gogo/errors.As.

func Is

func Is(err, target error) bool

Is directly calls the standard errors.Is.

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError reports whether the specified error is encountered during sending an HTTP request and receiving the response.

func IsFileError

func IsFileError(err error) bool

IsFileError reports whether the specified error is caused by operating a file or file path.

func IsProtoBufError

func IsProtoBufError(err error) bool

IsProtoBufError reports whether the specified error is encountered during reading or writing ProtoBuf messages.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError reports whether the specified error is caused by a timeout.

func IsUnacceptableResponseError

func IsUnacceptableResponseError(err error) bool

IsUnacceptableResponseError reports whether the specified error is caused by an unacceptable HTTP response.

func Join added in v0.4.0

func Join(errs ...error) error

Join directly calls the standard errors.Join.

func New

func New(msg string) error

New directly calls the standard errors.New.

func Unwrap

func Unwrap(err error) error

Unwrap directly calls the standard errors.Unwrap.

Types

type ProtoBufError

type ProtoBufError struct {
	Op   string // Op is the name of the operation that caused the error.
	Type string // Type is the type name of the operand.
	Err  error  // Err is the error reading or writing ProtoBuf messages.
}

ProtoBufError records an error reading or writing ProtoBuf messages and the operation that caused it.

func NewProtoBufError

func NewProtoBufError(Op string, v any, err error) *ProtoBufError

NewProtoBufError creates a new *ProtoBufError.

It records the specified operation name (Op) and error (err).

It records the type name according to v. If v is nil, it records the type name as "<nil>". If v is an interface or a pointer, and v is non-nil, it repeatedly replaces v with the element of v (i.e., the value that the interface v contains or that the pointer v points to) until v is neither an interface nor a pointer or v is nil. Otherwise, it records the type name of v.

func (*ProtoBufError) Error

func (e *ProtoBufError) Error() string

func (*ProtoBufError) Unwrap

func (e *ProtoBufError) Unwrap() error

type UnacceptableResponseError

type UnacceptableResponseError struct {
	StatusCode int    // StatusCode is the status code of the response, set only if unexpected.
	Status     string // Status is the status of the response, set only if unexpected.
	ReadError  error  // ReadError is the error reading the response body.
	Body       string // Body is the body of the response.

	// WantBody is the expected body of the response,
	// set only if no error occurs when reading the response body.
	WantBody string
}

UnacceptableResponseError records an unacceptable HTTP response, including unexpected response status, errors reading the response body, and unexpected response body.

func (*UnacceptableResponseError) Error

func (e *UnacceptableResponseError) Error() string

func (*UnacceptableResponseError) Unwrap

func (e *UnacceptableResponseError) Unwrap() error

Unwrap returns the error reading the response body.

Jump to

Keyboard shortcuts

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