errors

package
v0.56.5 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Unlicense Imports: 1 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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

View Source
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

View Source
var (
	ErrDatabaseUnavailable = NewStorageError(
		"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

View Source
var (
	ErrServiceUnavailable = NewServiceError(
		"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

func Category(err error) string

Category returns the category of a domain error, or "unknown" for other errors.

func Code

func Code(err error) string

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

func IsAuthorization(err error) bool

IsAuthorization checks if an error is an authorization error.

func IsPolicy

func IsPolicy(err error) bool

IsPolicy checks if an error is a policy error.

func IsProcessing

func IsProcessing(err error) bool

IsProcessing checks if an error is a processing error.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable checks if an error indicates the operation can be retried.

func IsStorage

func IsStorage(err error) bool

IsStorage checks if an error is a storage error.

func IsValidation

func IsValidation(err error) bool

IsValidation checks if an error is a validation error.

func NeedsAuth

func NeedsAuth(err error) bool

NeedsAuth checks if an authorization error requires authentication.

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) Category

func (e *Base) Category() string

func (*Base) Code

func (e *Base) Code() string

func (*Base) Error

func (e *Base) Error() string

func (*Base) IsRetryable

func (e *Base) IsRetryable() bool

func (*Base) Unwrap

func (e *Base) Unwrap() error

func (*Base) WithCause

func (e *Base) WithCause(cause error) *Base

WithCause returns a copy of the error with the given cause.

func (*Base) WithMessage

func (e *Base) WithMessage(msg string) *Base

WithMessage returns a copy of the error with the given message.

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

type ServiceError struct {
	Base
	ServiceName string
}

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

type ValidationError struct {
	Base
	Field string // The field that failed validation
}

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

Jump to

Keyboard shortcuts

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