Documentation
¶
Overview ¶
Package errors provides domain-specific error types for the ORLY relay. These typed errors enable structured error handling, machine-readable error codes, and proper error categorization throughout the codebase.
Index ¶
- Variables
- func Category(err error) string
- func Code(err error) string
- func Is(err error, target DomainError) bool
- func IsAuthorization(err error) bool
- func IsPolicy(err error) bool
- func IsProcessing(err error) bool
- func IsRetryable(err error) bool
- func IsStorage(err error) bool
- func IsValidation(err error) bool
- func NeedsAuth(err error) bool
- type AuthorizationError
- type Base
- type DomainError
- type PolicyError
- type ProcessingError
- type ServiceError
- type StorageError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidEventID = NewValidationError( "INVALID_ID", "id", "event ID does not match computed hash", ) ErrInvalidSignature = NewValidationError( "INVALID_SIG", "sig", "signature verification failed", ) ErrFutureTimestamp = NewValidationError( "FUTURE_TS", "created_at", "timestamp too far in future", ) ErrPastTimestamp = NewValidationError( "PAST_TS", "created_at", "timestamp too far in past", ) ErrUppercaseHex = NewValidationError( "UPPERCASE_HEX", "id/pubkey", "hex values must be lowercase", ) ErrProtectedTagMismatch = NewValidationError( "PROTECTED_TAG", "tags", "protected event can only be modified by author", ) ErrInvalidJSON = NewValidationError( "INVALID_JSON", "", "malformed JSON", ) ErrEventTooLarge = NewValidationError( "EVENT_TOO_LARGE", "content", "event exceeds size limit", ) ErrInvalidKind = NewValidationError( "INVALID_KIND", "kind", "event kind not allowed", ) ErrMissingTag = NewValidationError( "MISSING_TAG", "tags", "required tag missing", ) ErrInvalidTagValue = NewValidationError( "INVALID_TAG", "tags", "tag value validation failed", ) )
Validation error constants
var ( ErrAuthRequired = NewAuthRequired("authentication required") ErrBanned = &AuthorizationError{ Base: Base{ code: "BANNED", category: "authorization", message: "pubkey banned", }, } ErrIPBlocked = &AuthorizationError{ Base: Base{ code: "IP_BLOCKED", category: "authorization", message: "IP address blocked", }, } ErrNotFollowed = &AuthorizationError{ Base: Base{ code: "NOT_FOLLOWED", category: "authorization", message: "write access requires being followed by admin", }, } ErrNotMember = &AuthorizationError{ Base: Base{ code: "NOT_MEMBER", category: "authorization", message: "membership required", }, } ErrInsufficientAccess = &AuthorizationError{ Base: Base{ code: "INSUFFICIENT_ACCESS", category: "authorization", message: "insufficient access level", }, } )
Authorization error constants
var ( ErrDuplicate = NewProcessingError( "DUPLICATE", "event already exists", false, ) ErrReplaceNotAllowed = NewProcessingError( "REPLACE_DENIED", "cannot replace event from different author", false, ) ErrDeletedEvent = NewProcessingError( "DELETED", "event has been deleted", false, ) ErrEphemeralNotStored = NewProcessingError( "EPHEMERAL", "ephemeral events are not stored", false, ) ErrRateLimited = NewProcessingError( "RATE_LIMITED", "rate limit exceeded", true, ) ErrSprocketRejected = NewProcessingError( "SPROCKET_REJECTED", "rejected by sprocket", false, ) )
Processing error constants
var ( ErrKindBlocked = &PolicyError{ Base: Base{ code: "KIND_BLOCKED", category: "policy", message: "event kind not allowed by policy", }, Action: "block", } ErrPubkeyBlocked = &PolicyError{ Base: Base{ code: "PUBKEY_BLOCKED", category: "policy", message: "pubkey blocked by policy", }, Action: "block", } ErrContentBlocked = &PolicyError{ Base: Base{ code: "CONTENT_BLOCKED", category: "policy", message: "content blocked by policy", }, Action: "block", } ErrScriptRejected = &PolicyError{ Base: Base{ code: "SCRIPT_REJECTED", category: "policy", message: "rejected by policy script", }, Action: "reject", } )
Policy error constants
var ( "DB_UNAVAILABLE", "database not available", nil, true, ) ErrWriteTimeout = NewStorageError( "WRITE_TIMEOUT", "write operation timed out", nil, true, ) ErrReadTimeout = NewStorageError( "READ_TIMEOUT", "read operation timed out", nil, true, ) ErrStorageFull = NewStorageError( "STORAGE_FULL", "storage capacity exceeded", nil, false, ) ErrCorruptedData = NewStorageError( "CORRUPTED_DATA", "data corruption detected", nil, false, ) )
Storage error constants
var ( "SERVICE_UNAVAILABLE", "", "service temporarily unavailable", true, ) ErrServiceTimeout = NewServiceError( "SERVICE_TIMEOUT", "", "service request timed out", true, ) ErrServiceOverloaded = NewServiceError( "SERVICE_OVERLOADED", "", "service is overloaded", true, ) )
Service error constants
Functions ¶
func Category ¶
Category returns the category of a domain error, or "unknown" for other errors.
func Code ¶
Code returns the error code if err is a DomainError, empty string otherwise.
func Is ¶
func Is(err error, target DomainError) bool
Is checks if an error matches a target domain error by code.
func IsAuthorization ¶
IsAuthorization checks if an error is an authorization error.
func IsProcessing ¶
IsProcessing checks if an error is a processing error.
func IsRetryable ¶
IsRetryable checks if an error indicates the operation can be retried.
func IsValidation ¶
IsValidation checks if an error is a validation error.
Types ¶
type AuthorizationError ¶
type AuthorizationError struct {
Base
Pubkey []byte // The pubkey that was denied
AccessLevel string // The access level that was required
RequireAuth bool // Whether authentication might resolve this
}
AuthorizationError represents an authorization failure.
func NewAccessDenied ¶
func NewAccessDenied(level, reason string) *AuthorizationError
NewAccessDenied creates an error indicating access was denied.
func NewAuthRequired ¶
func NewAuthRequired(reason string) *AuthorizationError
NewAuthRequired creates an error indicating authentication is required.
func (*AuthorizationError) NeedsAuth ¶
func (e *AuthorizationError) NeedsAuth() bool
NeedsAuth returns true if authentication might resolve this error.
func (*AuthorizationError) WithPubkey ¶
func (e *AuthorizationError) WithPubkey(pubkey []byte) *AuthorizationError
WithPubkey returns a copy with the specified pubkey.
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base provides common implementation for all domain errors.
func (*Base) WithCause ¶
WithCause returns a copy of the error with the given cause.
type DomainError ¶
type DomainError interface {
error
Code() string // Machine-readable error code (e.g., "INVALID_ID")
Category() string // Error category for grouping (e.g., "validation")
IsRetryable() bool // Whether the operation can be retried
}
DomainError is the base interface for all domain errors. It extends the standard error interface with structured metadata.
type PolicyError ¶
type PolicyError struct {
Base
RuleName string // The rule that was violated
Action string // The action taken (block, reject)
}
PolicyError represents a policy violation.
func NewPolicyBlocked ¶
func NewPolicyBlocked(ruleName, reason string) *PolicyError
NewPolicyBlocked creates an error for a blocked event.
func NewPolicyRejected ¶
func NewPolicyRejected(ruleName, reason string) *PolicyError
NewPolicyRejected creates an error for a rejected event.
type ProcessingError ¶
type ProcessingError struct {
Base
EventID []byte // The event ID (if known)
Kind uint16 // The event kind (if known)
}
ProcessingError represents an error during event processing.
func NewProcessingError ¶
func NewProcessingError(code string, message string, retryable bool) *ProcessingError
NewProcessingError creates a new processing error.
func (*ProcessingError) WithEventID ¶
func (e *ProcessingError) WithEventID(id []byte) *ProcessingError
WithEventID returns a copy with the specified event ID.
func (*ProcessingError) WithKind ¶
func (e *ProcessingError) WithKind(kind uint16) *ProcessingError
WithKind returns a copy with the specified kind.
type ServiceError ¶
ServiceError represents a service-level error.
func NewServiceError ¶
func NewServiceError(code, service, message string, retryable bool) *ServiceError
NewServiceError creates a new service error.
type StorageError ¶
type StorageError struct {
Base
}
StorageError represents a storage-layer error.
func NewStorageError ¶
func NewStorageError(code, message string, cause error, retryable bool) *StorageError
NewStorageError creates a new storage error.
type ValidationError ¶
ValidationError represents an error in event validation.
func NewValidationError ¶
func NewValidationError(code, field, message string) *ValidationError
NewValidationError creates a new validation error.
func (*ValidationError) WithField ¶
func (e *ValidationError) WithField(field string) *ValidationError
WithField returns a copy with the specified field.
Source Files
¶
- errors.go