errors

package
v0.0.69 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

This package provides a structured error type and functions to work with it. It is largely based on the work of Ben Johnson. Reference: https://www.gobeyond.dev/failure-is-your-domain/.

Index

Constants

View Source
const (
	CodeConflict = "conflict"
	CodeInternal = "internal"
	CodeInvalid  = "invalid"
	CodeNotFound = "notFound"
)

Pre-defined error codes.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

func ErrorCode

func ErrorCode(err error) string

func ErrorMessage

func ErrorMessage(err error) string

func Is

func Is(err, target error) bool

func LogAndWriteRESError

func LogAndWriteRESError(l errorLogger, w errorWriter, err error)

LogAndWriteRESError with the given logger and writer.

func MapSQLError

func MapSQLError(err error) error

MapSQLError into a well-defined error.

Types

type Error

type Error struct {
	// Code is machine-readable.
	Code string

	// Message is human-readable.
	Message string

	// Operation that caused the error.
	Operation string

	// UnderlyingError that caused this error, if any.
	UnderlyingError error
}

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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