errors

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors defines error types and utilities for TableTheory

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrItemNotFound is returned when an item is not found in the database
	ErrItemNotFound = errors.New("item not found")

	// ErrInvalidModel is returned when a model struct is invalid
	ErrInvalidModel = errors.New("invalid model")

	// ErrMissingPrimaryKey is returned when a model doesn't have a primary key
	ErrMissingPrimaryKey = errors.New("missing primary key")

	// ErrInvalidPrimaryKey is returned when a primary key value is invalid
	ErrInvalidPrimaryKey = errors.New("invalid primary key")

	// ErrConditionFailed is returned when a condition check fails
	ErrConditionFailed = errors.New("condition check failed")

	// ErrVersionConflict is returned when an optimistic-lock version condition fails.
	// It matches ErrConditionFailed via errors.Is for backward compatibility.
	ErrVersionConflict = conditionSubtypeError("version conflict")

	// ErrThrottled is returned when DynamoDB rejects an operation due to throttling.
	ErrThrottled = errors.New("throttled")

	// ErrTransactionConflict is returned when DynamoDB reports a transaction conflict.
	// It matches ErrTransactionFailed via errors.Is for backward compatibility.
	ErrTransactionConflict = transactionSubtypeError("transaction conflict")

	// ErrIndexNotFound is returned when a specified index doesn't exist
	ErrIndexNotFound = errors.New("index not found")

	// ErrTransactionFailed is returned when a transaction fails
	ErrTransactionFailed = errors.New("transaction failed")

	// ErrBatchOperationFailed is returned when a batch operation partially fails
	ErrBatchOperationFailed = errors.New("batch operation failed")

	// ErrUnsupportedType is returned when a field type is not supported
	ErrUnsupportedType = errors.New("unsupported type")

	// ErrInvalidTag is returned when a struct tag is invalid
	ErrInvalidTag = errors.New("invalid struct tag")

	// ErrTableNotFound is returned when a table doesn't exist
	ErrTableNotFound = errors.New("table not found")

	// ErrDuplicatePrimaryKey is returned when multiple primary keys are defined.
	// It matches ErrInvalidModel via errors.Is because duplicate keys are invalid model shapes.
	// Its declared error type is part of the published API contract.
	ErrDuplicatePrimaryKey error = invalidModelSubtypeError("duplicate primary key definition")

	// ErrEmptyValue is returned when a required value is empty
	ErrEmptyValue = errors.New("empty value")

	// ErrNoUpdatableFields is returned when an update selects no field the caller
	// can write, so there is no assignment to apply.
	ErrNoUpdatableFields = errors.New("no non-key fields to update")

	// ErrInvalidOperator is returned when an invalid query operator is used
	ErrInvalidOperator = errors.New("invalid query operator")

	// ErrEncryptionNotConfigured is returned when a model uses theorydb:"encrypted" fields but no KMS key ARN is configured.
	ErrEncryptionNotConfigured = errors.New("encryption not configured")

	// ErrInvalidEncryptedEnvelope is returned when an encrypted attribute value is not a valid TableTheory envelope.
	ErrInvalidEncryptedEnvelope = errors.New("invalid encrypted envelope")

	// ErrEncryptedFieldNotQueryable is returned when a theorydb:"encrypted" field is used in query/filter conditions.
	ErrEncryptedFieldNotQueryable = errors.New("encrypted fields are not queryable/filterable")

	// ErrImmutableModelMutation is returned when a write-once model is mutated through a generic high-level API.
	ErrImmutableModelMutation = errors.New("immutable model mutation")

	// ErrProtectedFieldMutation is returned when a protected model attribute is mutated through a generic high-level API.
	ErrProtectedFieldMutation = errors.New("protected field mutation")

	// ErrRejectedDeployAuthorityEvidence is returned when provenance/confidence evidence is not deploy-authoritative.
	ErrRejectedDeployAuthorityEvidence = errors.New("rejected deploy authority evidence")
)

Common errors that can occur in TableTheory operations

Functions

func IsConditionFailed

func IsConditionFailed(err error) bool

IsConditionFailed checks if an error indicates a condition check failure

func IsInvalidModel

func IsInvalidModel(err error) bool

IsInvalidModel checks if an error indicates an invalid model

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if an error indicates an item was not found

Types

type CancellationReason

type CancellationReason struct {
	Code    string
	Message string
	Index   int
}

CancellationReason captures a single entry of a DynamoDB transaction cancellation reason list in its original position.

It deliberately carries only the classification code and the service message: the DynamoDB item image (the cancellation reason's Item attribute map) is never copied here, so reasons are always safe to log. Entries whose code is missing or the "None" placeholder keep their position with an empty Code so Index stays aligned with the transaction operations.

type EncryptedFieldError

type EncryptedFieldError struct {
	Err       error
	Field     string
	Operation string
}

EncryptedFieldError wraps failures related to theorydb:"encrypted" fields (encryption/decryption). It is safe-by-default: the error string must never include decrypted plaintext.

func (*EncryptedFieldError) Error

func (e *EncryptedFieldError) Error() string

func (*EncryptedFieldError) Unwrap

func (e *EncryptedFieldError) Unwrap() error

type TheorydbError

type TheorydbError struct {
	Err     error
	Context map[string]any
	Op      string
	Model   string
}

TheorydbError represents a detailed error with context

func NewError

func NewError(op, model string, err error) *TheorydbError

NewError creates a new TheorydbError

func NewErrorWithContext

func NewErrorWithContext(op, model string, err error, context map[string]any) *TheorydbError

NewErrorWithContext creates a new TheorydbError with context

func (*TheorydbError) Error

func (e *TheorydbError) Error() string

Error implements the error interface

func (*TheorydbError) Is

func (e *TheorydbError) Is(target error) bool

Is checks if the error matches the target error

func (*TheorydbError) Unwrap

func (e *TheorydbError) Unwrap() error

Unwrap returns the underlying error

type TransactionError

type TransactionError struct {
	Err error

	// Cause is the original error that produced the transaction failure. For a
	// DynamoDB transaction cancellation it is the SDK's
	// *types.TransactionCanceledException (wrapped errors preserved), so callers
	// can recover the exception and its ordered CancellationReasons with
	// errors.As. Error() never consults Cause, so logging stays free of item
	// images; a caller that inspects Cause directly owns that decision.
	Cause error

	Operation string
	Model     string
	Reason    string

	// Reasons carries every entry of the DynamoDB cancellation reason list in
	// its original order, including entries with a missing or "None" code, so
	// positions stay aligned with the transaction operations. Use RealFailures
	// to iterate only the genuine failures.
	Reasons []CancellationReason

	// OperationIndex is the position of the first genuine per-operation failure.
	// It is -1 for a cancellation with no genuine per-operation failure — an empty
	// reason list, or every reason missing its code or carrying the "None"
	// placeholder. That deliberate marker keeps the case distinct from a real
	// failure at operation 0; see
	// TestTransactionCancellationAllNoneIsGenericNotConditional in pkg/transaction.
	OperationIndex int
}

TransactionError provides context for transactional failures.

func (*TransactionError) As

func (e *TransactionError) As(target any) bool

As lets errors.As recover the original failure stored in Cause and therefore the AWS exception (with its ordered CancellationReasons). It delegates to errors.As on Cause and guards nil and a self-referential cause so it can never recurse into itself. errors.Is sentinel matching is unaffected.

func (*TransactionError) Error

func (e *TransactionError) Error() string

Error implements the error interface.

func (*TransactionError) RealFailures

func (e *TransactionError) RealFailures() []CancellationReason

RealFailures returns the cancellation reasons that represent genuine failures, in original order: every entry with a non-empty code that is not DynamoDB's "None" placeholder. The returned slice may be empty.

func (*TransactionError) Unwrap

func (e *TransactionError) Unwrap() error

Unwrap returns the underlying classified error. It stays a single-error Unwrap (not the []error form) so errors.Unwrap keeps returning the sentinel for existing callers.

Jump to

Keyboard shortcuts

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