werr

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotABoolean      = NewTypeSentinel("boolean")
	ErrNotAPort         = NewTypeSentinel("port")
	ErrNotAnInputPort   = NewTypeSentinel("input port")
	ErrNotAnOutputPort  = NewTypeSentinel("output port")
	ErrNotABox          = NewTypeSentinel("box")
	ErrNotAnOpaqueValue = NewTypeSentinel("opaque value")
	ErrNotAByte         = NewTypeSentinel("byte")
	// "binary" matches the user-facing terminology used in R7RS and
	// values/value_type.go; the var name keeps "Byte" for historical
	// reasons but the message phrase tracks the rest of the codebase.
	ErrNotAByteInputPort      = NewTypeSentinel("binary input port")
	ErrNotAByteOutputPort     = NewTypeSentinel("binary output port")
	ErrNotATextualPort        = NewTypeSentinel("textual port")
	ErrStopIteration          = NewStaticError("stop iteration")
	ErrNotAPrimitive          = NewTypeSentinel("primitive")
	ErrNoSuchBinding          = NewStaticError("no such binding")
	ErrNotANumber             = NewTypeSentinel("number")
	ErrCannotCompare          = NewStaticError("cannot compare values")
	ErrNotAReal               = NewTypeSentinel("real number")
	ErrDivisionByZero         = NewStaticError("division by zero")
	ErrNotAList               = NewTypeSentinel("list")
	ErrNotACloseParen         = NewStaticError("not a close parenthesis")
	ErrWrongNumberOfArguments = NewStaticError("wrong number of arguments")
	ErrNotAMachineContext     = NewTypeSentinel("machine context")
	ErrNotAPair               = NewTypeSentinel("pair")
	ErrNotACons               = NewTypeSentinel("cons")
	ErrNotACharacter          = NewTypeSentinel("character")
	ErrNotACharSet            = NewTypeSentinel("char-set")
	ErrStackUnderflow         = NewStaticError("stack underflow")
	ErrStackOverflow          = NewStaticError("stack overflow")
	ErrNotASyntaxValue        = NewTypeSentinel("syntax value")
	ErrNotASyntaxPair         = NewTypeSentinel("syntax pair")
	ErrNotASyntaxSymbol       = NewTypeSentinel("syntax symbol")
	ErrNotASyntaxList         = NewTypeSentinel("syntax list")
	ErrNotASyntaxObject       = NewTypeSentinel("syntax object")
	ErrNotASymbol             = NewTypeSentinel("symbol")
	ErrInvalidSyntax          = NewStaticError("invalid syntax")
	// ErrIncompleteInput marks input that is a valid prefix of an expression but
	// ended before completing (unterminated string/symbol, source ending inside an
	// unclosed form). REPLs errors.Is this to decide whether to read more input.
	// Lives in werr (not internal/parser) so the tokenizer can reference it without
	// an import cycle.
	ErrIncompleteInput           = NewStaticError("incomplete input")
	ErrInvalidArgument           = NewStaticError("invalid argument")
	ErrInternal                  = NewStaticError("internal error")
	ErrDuplicateBinding          = NewStaticError("duplicate binding")
	ErrNotAClosure               = NewTypeSentinel("closure")
	ErrUnknownCharacterMnemonic  = NewStaticError("unknown character mnemonic")
	ErrNotAnInteger              = NewTypeSentinel("integer")
	ErrNotALocalEnvironmentFrame = NewTypeSentinel("local environment frame")
	ErrNotAMachineTemplate       = NewTypeSentinel("machine template")
	ErrUnexpectedNil             = NewStaticError("unexpected nil value")
	ErrUnexpectedTransformer     = NewStaticError("unexpected transformer")
	ErrNotAString                = NewTypeSentinel("string")
	ErrNotANamespace             = NewTypeSentinel("namespace")
	ErrNotAVector                = NewTypeSentinel("vector")
	ErrNotAByteVector            = NewTypeSentinel("bytevector")
	ErrNotAProcedure             = NewTypeSentinel("procedure")
	ErrNotAParameter             = NewTypeSentinel("parameter")
	// ErrComposableContinuationFromGo marks an attempt to invoke a composable
	// continuation from Go via Engine.Call; composable continuations require the
	// VM winding stack and have no Go-callable form.
	ErrComposableContinuationFromGo = NewStaticError("cannot call composable continuation from Go")
	ErrNotAStringOutputPort         = NewTypeSentinel("string output port")
	ErrNotABytevectorOutputPort     = NewTypeSentinel("bytevector output port")
	ErrNotANativeError              = NewTypeSentinel("error object")
	ErrNotARecord                   = NewTypeSentinel("record")
	ErrNotARecordType               = NewTypeSentinel("record type")
	ErrOpaqueRecord                 = NewStaticError("record type is opaque")
	ErrFileNotFound                 = NewStaticError("file not found")
	ErrFileOpen                     = NewStaticError("file open failed")
	ErrLibraryNotFound              = NewStaticError("library not found")
	ErrCircularDependency           = NewStaticError("circular library dependency")
	ErrUnexportedIdentifier         = NewStaticError("identifier not exported")

	// Threading errors
	ErrNotAThread            = NewTypeSentinel("thread")
	ErrNotAMutex             = NewTypeSentinel("mutex")
	ErrNotAConditionVariable = NewTypeSentinel("condition variable")
	ErrNotATime              = NewTypeSentinel("time")
	ErrNotAChannel           = NewTypeSentinel("channel")
	ErrNotAWaitGroup         = NewTypeSentinel("wait-group")
	ErrNotARWMutex           = NewTypeSentinel("rw-mutex")
	// "once" is pronounced /wuns/ — letter rule would give "an once", but
	// the consonant /w/ sound calls for "a". Pass-through preserves the
	// correct article.
	ErrNotAOnce                = NewTypeSentinel("a once")
	ErrNotAnAtomic             = NewTypeSentinel("atomic")
	ErrPortClosed              = NewStaticError("port is closed")
	ErrNotAHashtable           = NewTypeSentinel("hashtable")
	ErrNoCaptureContext        = NewStaticError("no capture context for expansion")
	ErrExactnessConversion     = NewStaticError("exactness conversion failed")
	ErrLossyConversion         = NewStaticError("lossy conversion")
	ErrNumericRegistry         = NewStaticError("numeric registry violation")
	ErrInvalidFormat           = NewStaticError("invalid number format")
	ErrUnknownOpCode           = NewStaticError("unknown op code")
	ErrNotAMatch               = NewTypeSentinel("match")
	ErrNotAPromptTag           = NewTypeSentinel("prompt tag")
	ErrNotAContinuationMarkSet = NewTypeSentinel("continuation mark set")
	ErrNotAContinuation        = NewTypeSentinel("continuation")
	ErrNotAnErrorContext       = NewTypeSentinel("error context")
	ErrTypeConversion          = NewStaticError("type conversion failed")
	ErrCodepointOutOfRange     = NewStaticError("codepoint out of range")
	ErrIndexOutOfRange         = NewStaticError("index out of range")
	ErrImmutableString         = NewStaticError("cannot mutate immutable string")
	ErrImmutablePair           = NewStaticError("cannot mutate immutable pair")
	ErrImmutableVector         = NewStaticError("cannot mutate immutable vector")
	ErrImmutableBytevector     = NewStaticError("cannot mutate immutable bytevector")
	ErrImmutableBinding        = NewStaticError("cannot mutate immutable binding")
	ErrInvariantViolation      = NewStaticError("invariant violation")

	// FFI errors
	ErrFFIRegistration          = NewStaticError("FFI registration error")
	ErrFFICallbackError         = NewStaticError("FFI callback error")
	ErrCallbackResultConversion = NewStaticError("callback result conversion failed")
	ErrHashtableInsertionFailed = NewStaticError("hashtable insertion failed")

	// Engine initialization errors
	ErrEngineInit = NewStaticError("engine initialization error")

	// Pipeline errors (expansion, compilation, runtime phases)
	ErrExpansion   = NewStaticError("expansion error")
	ErrCompilation = NewStaticError("compilation error")

	// Environment errors (keep as panics but use sentinels)
	ErrMissingNamespace     = NewStaticError("missing Namespace")
	ErrMissingPhaseRegistry = NewStaticError("missing PhaseRegistry")
	ErrNilParentEnvironment = NewStaticError("nil parent environment")

	// Panic recovery errors
	ErrThreadPanic   = NewStaticError("thread panic")
	ErrPanicRecovery = NewStaticError("panic recovery")

	// Syntax errors
	ErrCannotDoubleSyntaxWrap  = NewStaticError("cannot wrap syntax value in SyntaxObject")
	ErrNoMatchingClause        = NewStaticError("no matching clause")
	ErrUnsupportedTransformer  = NewStaticError("unsupported transformer")
	ErrLibraryConfiguration    = NewStaticError("library configuration error")
	ErrLibraryFormMalformed    = NewStaticError("malformed library form")
	ErrLibraryNameMismatch     = NewStaticError("library name mismatch")
	ErrHashtableKeyNotFound    = NewStaticError("hashtable key not found")
	ErrAllocationLimitExceeded = NewStaticError("allocation limit exceeded")
	ErrNonContinuableException = NewStaticError("non-continuable exception")

	// Recursion depth
	ErrCallDepthExceeded     = NewStaticError("call depth exceeded")
	ErrParseDepthExceeded    = NewStaticError("parse nesting depth exceeded")
	ErrExpandDepthExceeded   = NewStaticError("macro expansion nesting depth exceeded")
	ErrContinuationUnderflow = NewStaticError("continuation underflow")

	// Escape continuations
	ErrExpiredEscape       = NewStaticError("expired escape procedure")
	ErrContinuationBarrier = NewStaticError("continuation barrier violation")

	// Utility errors (keep as panic)
	ErrRandomGenerationFailed = NewStaticError("random generation failed")
	ErrInvalidLoadPath        = NewStaticError("invalid load path")

	// Channel errors
	ErrChannelClosed = NewStaticError("channel is closed")

	// Process errors
	ErrNotAProcess = NewTypeSentinel("process")

	// Thread errors
	ErrJoinTimeout             = NewStaticError("thread-join!: timeout")
	ErrThreadAlreadyStarted    = NewStaticError("thread-start!: thread already started")
	ErrCrossThreadContinuation = NewStaticError("cannot invoke continuation from different thread")
)

Standard error values for type checking and runtime errors.

Functions

func TypeNameOf added in v1.17.0

func TypeNameOf(err error) string

TypeNameOf extracts the expected-type phrase from any error wrapping a type-mismatch sentinel. Returns "" for non-sentinel errors or sentinels without a type name. Use this in helpers that format error messages from a sentinel parameter — it works regardless of where the helper lives in the dependency graph.

Types

type ForeignError

type ForeignError struct {
	// contains filtered or unexported fields
}

ForeignError is an error type for Go primitive implementations (functions foreign to Scheme). It wraps an optional underlying error with a message.

func NewForeignErrorf

func NewForeignErrorf(msg string, vs ...any) *ForeignError

NewForeignErrorf creates a new foreign error with a formatted message.

func WrapForeignErrorWithCause

func WrapForeignErrorWithCause(sentinel, cause error, msg string, vs ...any) *ForeignError

WrapForeignErrorWithCause wraps a sentinel and a root cause into a single ForeignError. The sentinel is matched by errors.Is for programmatic dispatch; the cause preserves the underlying failure for diagnostics.

func WrapForeignErrorf

func WrapForeignErrorf(err error, msg string, vs ...any) *ForeignError

WrapForeignErrorf wraps an existing error with a formatted message.

func (*ForeignError) As

func (p *ForeignError) As(target any) bool

As checks whether the sentinel or cause can be assigned to target.

func (*ForeignError) Cause

func (p *ForeignError) Cause() error

Cause returns the root cause error, if any. Useful for debugging/logging when you need the underlying failure directly.

func (*ForeignError) Error

func (p *ForeignError) Error() string

func (*ForeignError) Is

func (p *ForeignError) Is(target error) bool

Is reports whether target matches the sentinel or the cause. This replaces Unwrap and gives ForeignError precise two-chain semantics: the sentinel identifies the error category, the cause preserves the root failure from the underlying operation.

type ForeignFileError

type ForeignFileError struct {
	*ForeignError
	Filename string // the file path that caused the error
	Op       string // the operation (e.g., "open-input-file", "delete-file")
}

ForeignFileError represents an error from a file system operation. R7RS §6.11: detected by file-error? predicate.

func WrapForeignFileError

func WrapForeignFileError(err error, op string, filename string) *ForeignFileError

WrapForeignFileError wraps an OS error with file context.

type ForeignProcessError added in v1.9.1

type ForeignProcessError struct {
	*ForeignError
	Command string // the command that was run
	Op      string // the operation (e.g., "process-spawn", "system")
}

ForeignProcessError represents an error from a process operation. Parallel to ForeignFileError for programmatic inspection of failed process operations.

func WrapForeignProcessError added in v1.9.1

func WrapForeignProcessError(err error, op string, command string) *ForeignProcessError

WrapForeignProcessError wraps an OS error with process context.

type ForeignReadError

type ForeignReadError struct {
	*ForeignError
}

ForeignReadError represents an error from a read or parse operation. R7RS §6.11: detected by read-error? predicate.

func NewForeignReadErrorf

func NewForeignReadErrorf(msg string, vs ...any) *ForeignReadError

NewForeignReadErrorf creates a new read error with a formatted message.

func WrapForeignReadErrorf

func WrapForeignReadErrorf(err error, msg string, vs ...any) *ForeignReadError

WrapForeignReadErrorf wraps an error as a read error.

type StaticError

type StaticError struct {
	// contains filtered or unexported fields
}

StaticError is a sentinel error type for programmatic matching via errors.Is. Each sentinel carries a fixed human-readable message and serves as a stable identity that callers can match across error wrapping layers.

Type-mismatch sentinels (declared via NewTypeSentinel) additionally carry an expectedType phrase (e.g., "a string") used by argument-extraction helpers in registry/helpers to format error messages without each call site repeating the phrase.

func NewStaticError

func NewStaticError(msg string) *StaticError

NewStaticError creates a new static error with the given message. The returned sentinel has no expectedType; callers using it with type-checking helpers will get a degraded ("expected but got ...") error message. Use NewTypeSentinel for type-mismatch sentinels.

func NewTypeSentinel added in v1.16.0

func NewTypeSentinel(noun string) *StaticError

NewTypeSentinel creates a sentinel for a type-mismatch error. The noun argument is the bare type-name ("string", "integer", "char-set", …); NewTypeSentinel auto-prefixes "a"/"an" using articleFor. The sentinel's Error() value is "not " + article + " " + noun, e.g. "not a string" or "not an integer".

For irregular cases where letter-based article selection produces the wrong result (e.g., "once" pronounced /wuns/ wants "a", not "an"), pass the already-articled phrase: NewTypeSentinel("a once"). Inputs starting with "a " or "an " are used verbatim.

Panics on empty noun — a type sentinel without a noun is a programmer bug, since the resulting "expected " phrase would be useless. Use NewStaticError for sentinels that aren't type-mismatch errors.

func (*StaticError) Error

func (p *StaticError) Error() string

func (*StaticError) TypeName added in v1.16.0

func (p *StaticError) TypeName() string

TypeName returns the expected-type phrase for type-mismatch sentinels (those constructed via NewTypeSentinel). Returns "" for sentinels constructed via NewStaticError.

Jump to

Keyboard shortcuts

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