errors

package
v0.0.0-...-c124da1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errors provides structured error types with gRPC-compatible codes for gofly services. It supports error wrapping, HTTP status code mapping, and sentinel error matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPCError

func GRPCError(err error) error

func GRPCStatus

func GRPCStatus(code Code) codes.Code

func GRPCStatusFromCode

func GRPCStatusFromCode(code Code) codes.Code

func HTTPStatus

func HTTPStatus(code Code) int

func HTTPStatusFromCode

func HTTPStatusFromCode(code Code) int

func MessageOf

func MessageOf(err error) string

func Retryable

func Retryable(err error) bool

func TextOf

func TextOf(err error) string

Types

type Code

type Code string

Code is a gRPC-compatible error code.

const (
	CodeOK                 Code = "ok"
	CodeCanceled           Code = "canceled"
	CodeUnknown            Code = "unknown"
	CodeInvalidArgument    Code = "invalid_argument"
	CodeDeadlineExceeded   Code = "deadline_exceeded"
	CodeNotFound           Code = "not_found"
	CodeAlreadyExists      Code = "already_exists"
	CodePermissionDenied   Code = "permission_denied"
	CodeResourceExhausted  Code = "resource_exhausted"
	CodeFailedPrecondition Code = "failed_precondition"
	CodeAborted            Code = "aborted"
	CodeOutOfRange         Code = "out_of_range"
	CodeUnimplemented      Code = "unimplemented"
	CodeInternal           Code = "internal"
	CodeUnavailable        Code = "unavailable"
	CodeDataLoss           Code = "data_loss"
	CodeUnauthenticated    Code = "unauthenticated"
)

func CodeFromGRPCStatus

func CodeFromGRPCStatus(code codes.Code) Code

func CodeOf

func CodeOf(err error) Code

type Error

type Error struct {
	Code Code   `json:"code"`
	Text string `json:"text"`
	Base error  `json:"-"`
}

Error is a structured error with a code, message, and optional wrapped cause.

func Errorf

func Errorf(code Code, format string, args ...any) *Error

Errorf creates a new Error with a formatted message.

func New

func New(code Code, text string) *Error

New creates a new Error with the given code and text.

func Wrap

func Wrap(code Code, text string, base error) *Error

Wrap creates a new Error that wraps base.

func (*Error) Error

func (e *Error) Error() string

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() codes.Code

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

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