Documentation ¶
Overview ¶
Package bacerrors provides a rich error type for detailed error handling in Go applications. It offers functionality for error wrapping, stack trace tracking, and additional context such as hints, retryability, and HTTP status codes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrorWithCode ¶ added in v1.5.0
IsErrorWithCode checks if an error is an Error with a specific ErrorCode.
Types ¶
type Error ¶ added in v1.5.0
type Error interface { error // Hint returns a string providing additional context or suggestions related to the error. Hint() string // Retryable indicates whether the operation that caused this error can be retried. Retryable() bool // FailsExecution indicates whether this error should cause the overall execution to fail. FailsExecution() bool // Details returns a map of string key-value pairs providing additional error context. Details() map[string]string // Code returns the ErrorCode associated with this error. Code() ErrorCode // Component returns the name of the system component where the error originated. Component() string // HTTPStatusCode returns the HTTP status code associated with this error. HTTPStatusCode() int // ErrorWrapped returns the full error message, including messages from wrapped errors. ErrorWrapped() string // Unwrap returns the next error in the error chain, if any. Unwrap() error // StackTrace returns a string representation of the stack trace where the error occurred. StackTrace() string // WithHint adds or updates the hint associated with the error. WithHint(hintFormat string, a ...any) Error // WithRetryable marks the error as retryable. WithRetryable() Error // WithFailsExecution marks the error as causing execution failure. WithFailsExecution() Error // WithDetails adds or updates the details associated with the error. WithDetails(details map[string]string) Error // WithDetail adds or updates a single detail associated with the error. WithDetail(key, value string) Error // WithCode sets the ErrorCode for this error. WithCode(code ErrorCode) Error // WithHTTPStatusCode sets the HTTP status code associated with this error. WithHTTPStatusCode(statusCode int) Error // WithComponent sets the component name where the error originated. WithComponent(component string) Error }
Error interface defines methods that provide additional fields and functionality for more detailed error handling. It implements the standard error interface and adds methods for providing hints, indicating retryability, execution impact, and additional details.
func New ¶ added in v1.5.0
New creates a new Error with only the message field set. It initializes the error with a stack trace and sets the component to "Bacalhau" by default.
func Wrap ¶ added in v1.5.0
Wrap creates a new Error that wraps an existing error. If the wrapped error is already a bacerrors.Error, it updates the wrapped error while preserving the original error's information. Otherwise, it creates a new Error that includes both the new message and the original error's message.
type ErrorCode ¶ added in v1.5.0
type ErrorCode string
const ( BadRequestError ErrorCode = "BadRequest" InternalError ErrorCode = "InternalError" NotFoundError ErrorCode = "NotFound" TimeOutError ErrorCode = "TimeOut" NotImplemented ErrorCode = "NotImplemented" ResourceExhausted ErrorCode = "ResourceExhausted" ResourceInUse ErrorCode = "ResourceInUse" VersionMismatch ErrorCode = "VersionMismatch" ValidationError ErrorCode = "ValidationError" TooManyRequests ErrorCode = "TooManyRequests" NetworkFailure ErrorCode = "NetworkFailure" ConfigurationError ErrorCode = "ConfigurationError" DatastoreFailure ErrorCode = "DatastoreFailure" RequestCancelled ErrorCode = "RequestCancelled" IOError ErrorCode = "IOError" UnknownError ErrorCode = "UnknownError" )