Documentation
¶
Overview ¶
Package errors provides custom error types for sync operations.
The core type is SyncError, which wraps underlying errors with structured context including the operation, component, error kind, and retryability information. Use the E() builder function for flexible error construction, or type-specific constructors (NewStorageError, NewNetworkError, etc.) for common cases.
Error Classification ¶
Errors are classified by Kind (Invalid, NotFound, Permission, Internal, Timeout, etc.) and ErrorCode (NetworkFailure, StorageFailure, etc.). This enables downstream handlers to apply appropriate retry logic and user-facing messaging.
See also:
- README: https://github.com/c0deZ3R0/go-sync-kit#readme
- Architecture overview: https://github.com/c0deZ3R0/go-sync-kit/blob/main/docs/overview.md
Package errors provides custom error types for the sync package
Index ¶
- func Component(component string) componentArg
- func IsRetryable(err error) bool
- func WrapOpComponent(err error, op, component string) error
- func WrapOpComponentKind(err error, op, component string, kind Kind) error
- type ErrorCode
- type Kind
- type Operation
- type SyncError
- func E(args ...interface{}) *SyncError
- func New(op Operation, err error) *SyncError
- func NewConflictError(op Operation, cause error) *SyncError
- func NewNetworkError(op Operation, cause error) *SyncError
- func NewRetryable(op Operation, err error) *SyncError
- func NewStorageError(op Operation, cause error) *SyncError
- func NewValidationError(op Operation, cause error) *SyncError
- func NewWithComponent(op Operation, component string, err error) *SyncError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Component ¶ added in v0.9.0
func Component(component string) componentArg
Component creates a component string argument for E() that's clearly distinguished from context messages
func IsRetryable ¶
IsRetryable checks if an error is a retryable SyncError.
func WrapOpComponent ¶ added in v0.16.0
WrapOpComponent provides a convenience helper to wrap errors with consistent Op and Component propagation. It avoids repetition when creating structured errors throughout the codebase. If err is nil, returns nil.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode represents the type of error that occurred.
const ( // ErrCodeNetworkFailure indicates a network-related error. ErrCodeNetworkFailure ErrorCode = "NETWORK_FAILURE" // ErrCodeStorageFailure indicates a storage-related error. ErrCodeStorageFailure ErrorCode = "STORAGE_FAILURE" // ErrCodeConflictFailure indicates a conflict resolution error. ErrCodeConflictFailure ErrorCode = "CONFLICT_FAILURE" // ErrCodeValidationFailure indicates a validation error. ErrCodeValidationFailure ErrorCode = "VALIDATION_FAILURE" )
type Kind ¶ added in v0.9.0
type Kind string
Kind represents the category of error for structured error handling.
const ( // KindInvalid indicates invalid input or request. KindInvalid Kind = "INVALID" // KindNotFound indicates a resource not found. KindNotFound Kind = "NOT_FOUND" // KindPermission indicates permission denied. KindPermission Kind = "PERMISSION" // KindInternal indicates an internal server error. KindInternal Kind = "INTERNAL" // KindTimeout indicates an operation timeout. KindTimeout Kind = "TIMEOUT" KindUnavailable Kind = "UNAVAILABLE" // KindConflict indicates a resource conflict. KindConflict Kind = "CONFLICT" // KindTooLarge indicates request too large. KindTooLarge Kind = "TOO_LARGE" // KindMethodNotAllowed indicates HTTP method not allowed. KindMethodNotAllowed Kind = "METHOD_NOT_ALLOWED" )
type Operation ¶
type Operation string
Operation represents the type of sync operation.
const ( // OpSync is a general sync operation. OpSync Operation = "sync" // OpPush is a push operation. OpPush Operation = "push" // OpPull is a pull operation. OpPull Operation = "pull" // OpStore is a store operation. OpStore Operation = "store" // OpLoad is a load operation. OpLoad Operation = "load" // OpConflictResolve is a conflict resolution operation. OpConflictResolve Operation = "conflict_resolve" // OpTransport is a transport operation. OpTransport Operation = "transport" // OpClose is a close operation. OpClose Operation = "close" // OpProjection is a projection operation. OpProjection Operation = "projection" // OpProjectionApply is a projection apply operation. OpProjectionApply Operation = "projection_apply" // OpOffsetStore is an offset store operation. OpOffsetStore Operation = "offset_store" )
type SyncError ¶
type SyncError struct {
// Operation during which the error occurred.
Op Operation
// Component that generated the error (e.g., "store", "transport").
Component string
// Err is the underlying error.
Err error
// Retryable indicates whether the operation can be retried.
Retryable bool
// Code is the error code for the error type.
Code ErrorCode
// Kind represents the category of error.
Kind Kind
// Metadata holds additional context.
Metadata map[string]interface{}
}
SyncError represents an error that occurred during synchronization.
func E ¶ added in v0.9.0
func E(args ...interface{}) *SyncError
E creates a structured error using a builder pattern. This function provides a flexible way to create errors with multiple attributes. Arguments can be provided in any order and include:
- Operation: specifies the operation during which the error occurred
- Component: specifies the component that generated the error (string)
- Kind: specifies the category of error
- error: the underlying error
- string: additional context message
Example:
err := E(Op("httptransport.handlePush"), Component("httptransport"), Kind(KindInvalid), underlyingErr, "decode request")
func NewConflictError ¶
NewConflictError creates a new conflict-related SyncError
func NewNetworkError ¶
NewNetworkError creates a new network-related SyncError
func NewRetryable ¶
NewRetryable creates a new retryable SyncError
func NewStorageError ¶
NewStorageError creates a new storage-related SyncError
func NewValidationError ¶
NewValidationError creates a new validation-related SyncError
func NewWithComponent ¶
NewWithComponent creates a new SyncError with component information