failure

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INVALID_ARGUMENT  = "INVALID_ARGUMENT"  // Request contains invalid parameters
	INVALID_OPERATION = "INVALID_OPERATION" // Operation not permitted in current state
	UNKNOWN_ERROR     = "UNKNOWN_ERROR"     // Unexpected system error
	NOP               = "NOP"               // No operation performed
	NO_CONTENT        = "NO_CONTENT"        // Request processed but no content returned
)

Standard failure message codes for consistent error handling.

Variables

This section is empty.

Functions

func IsKnownErrorCode

func IsKnownErrorCode(message string) bool

IsKnownErrorCode validates if message follows standard error code format. Error codes must be 1-64 characters, uppercase letters, numbers, and underscores only.

func ThrowFailure

func ThrowFailure(err error)

ThrowFailure converts an error to structured Failure and panics with it. Automatically categorizes errors based on type and message format.

func ThrowFailureMessage

func ThrowFailureMessage(message, reason string)

ThrowFailureMessage creates a Failure with custom message and reason, then panics. Validates message format and provides consistent error structure.

Types

type Failure

type Failure struct {
	Err         error           `json:"-"`
	Message     string          `json:"message"`
	Description string          `json:"description,omitempty"`
	TraceID     string          `json:"_trace_id,omitempty"`
	Reason      json.RawMessage `json:"reason,omitempty"`
	Timestamp   int64           `json:"timestamp"`
}

Failure represents a structured error response with context and tracing support. Provides JSON serialization and error chain unwrapping capabilities.

func (*Failure) Error

func (f *Failure) Error() string

Error returns the failure message, implementing the error interface.

func (*Failure) MarshalJSON

func (f *Failure) MarshalJSON() ([]byte, error)

MarshalJSON provides custom JSON serialization for proper API response format.

func (*Failure) Unwrap

func (f *Failure) Unwrap() error

Unwrap returns the underlying error for error chain unwrapping.

type WellKnownError

type WellKnownError interface {
	error
	GetMessage() string
	GetDescription() string
	GetReason() json.RawMessage
}

WellKnownError defines interface for structured error types. Provides standardized error information extraction methods.

Jump to

Keyboard shortcuts

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