Skip to content
6 min read · 1,132 words

@nhtio/adk/exceptions ​

Core ADK exception classes and reusable runtime error constructors.

Every exception has a stable E_* code. The fatal flag on each code controls whether it throws synchronously (programming error — no recovery path) or is emitted on the observability error bus (runtime failure — run() still resolves).

Classes ​

ClassDescription
ValidationExceptionThrown when input fails schema validation.

Variables ​

VariableDescription
E_ARTIFACT_ID_COLLISIONThrown when a tool call and retrievable eligible for artifact forging share an id.
E_TOKEN_ESTIMATOR_SHADOWS_BUILTINThrown by registerTokenEstimator when the given encoding identifier names a built-in TokenEncoding rather than a genuinely custom one.

Functions ​

FunctionDescription
asyncValidateOrThrowValidates value against schema asynchronously and returns the coerced result typed as T.
passesSchemaReturns true if value satisfies schema without throwing.
validateOrThrowValidates value against schema synchronously and returns the coerced result typed as T.

References ​

E_CONTEXT_RESOLVER_MISSING ​

Re-exports E_CONTEXT_RESOLVER_MISSING


E_SHIM_NOT_RESOLVED ​

Re-exports E_SHIM_NOT_RESOLVED


E_SHIM_RESOLUTION_FAILED ​

Re-exports E_SHIM_RESOLUTION_FAILED


E_SHIM_RESOLVER_ALREADY_RESOLVED ​

Re-exports E_SHIM_RESOLVER_ALREADY_RESOLVED

Artifacts ​

Exceptions from spool and media artifact construction. Fatal — wrap-site validation that the supplied value implements the required reader interface.

VariableDescription
E_INVALID_INITIAL_MEDIA_VALUEThrown when a Media is initialised with a value that fails schema validation.
E_NOT_A_MEDIA_READERThrown when a Media is constructed with a value that does not implement the MediaReader interface.
E_NOT_A_SPOOL_READERThrown when a @nhtio/adk!SpooledArtifact is constructed with a value that does not implement the @nhtio/adk!SpoolReader interface.

Dispatch ​

Exceptions from the dispatch loop and its executor. A mix of fatal (programming errors) and non-fatal (runtime failures that nack the dispatch). The loop terminates as 'ack', 'nack', or 'aborted' — inspect dispatchEnd.status to classify.

VariableDescription
E_INVALID_LLM_DISPATCH_INPUTThrown when @nhtio/adk!DispatchRunner.dispatch receives an input that fails schema validation.
E_INVALID_LLM_EXECUTION_CONTEXTThrown when @nhtio/adk!DispatchContext is constructed with a value that fails schema validation.
E_LLM_EXECUTION_ALREADY_SIGNALLEDThrown when @nhtio/adk!DispatchContext.ack or @nhtio/adk!DispatchContext.nack is called on a context that has already been signalled.
E_LLM_EXECUTION_EXECUTOR_ERROREmitted (via the observability error hook) and re-thrown when the user-supplied executor callback throws during @nhtio/adk!DispatchRunner.dispatch.
E_LLM_EXECUTION_GATE_NOT_SUPPORTEDThrown (as a rejection reason) when @nhtio/adk!DispatchContext.waitFor is called on a standalone context that was constructed without a waitFor function.

Gates ​

Exceptions from @nhtio/adk!TurnGate construction and settlement. All four settlement outcomes (resolved, invalid-resolution, aborted, timed-out) also emit turnGateClosed on the observability bus.

VariableDescription
E_INVALID_INITIAL_TURN_GATE_VALUEThrown when a @nhtio/adk!TurnGate is constructed with a value that fails schema validation.
E_INVALID_TURN_GATE_RESOLUTIONThrown synchronously in the caller's context when @nhtio/adk!TurnGate.resolve is called with a value that fails the gate's schema.
E_TURN_GATE_ABORTEDThrown (as a rejection reason) when a @nhtio/adk!TurnGate is aborted — either because the turn's AbortSignal fired or because @nhtio/adk!TurnGate.abort was called directly.
E_TURN_GATE_TIMEOUTThrown (as a rejection reason) when a @nhtio/adk!TurnGate times out before being resolved.

Pipelines ​

Non-fatal pipeline errors emitted on the observability error bus when middleware throws or a pipeline short-circuits. run() resolves; turnEnd still fires.

VariableDescription
E_DISPATCH_PIPELINE_ERROREmitted (via the observability error hook) and re-thrown when a non-abort error propagates out of the input or output middleware pipeline during @nhtio/adk!DispatchRunner.dispatch.
E_INPUT_PIPELINE_ERROREmitted (via the error event) when a non-abort error propagates out of the input middleware pipeline during @nhtio/adk!TurnRunner.run.
E_OUTPUT_PIPELINE_ERROREmitted (via the error event) when a non-abort error propagates out of the output middleware pipeline during @nhtio/adk!TurnRunner.run.
E_PIPELINE_SHORT_CIRCUITEDEmitted (via the error event) when a middleware pipeline resolves without reaching its terminal handler and without the turn being aborted. Indicates that some middleware returned without calling next and without signalling a deliberate refusal via the turn's abort controller.

Primitive Validation ​

Fatal exceptions thrown at construction time when a primitive (@nhtio/adk!Message, @nhtio/adk!Memory, @nhtio/adk!Thought, @nhtio/adk!ToolCall, @nhtio/adk!Retrievable, @nhtio/adk!Identity, @nhtio/adk!Registry) receives an invalid initial value. If a primitive constructed, it is valid.

VariableDescription
E_INVALID_INITIAL_IDENTITY_VALUEThrown when an @nhtio/adk!Identity is initialised with a value that fails schema validation.
E_INVALID_INITIAL_MEMORY_VALUEThrown when a @nhtio/adk!Memory is initialised with a value that fails schema validation.
E_INVALID_INITIAL_MESSAGE_VALUEThrown when a @nhtio/adk!Message is initialised with a value that fails schema validation.
E_INVALID_INITIAL_REGISTRY_VALUEThrown when a registry is initialised with a value that is defined but not a plain object.
E_INVALID_INITIAL_RETRIEVABLE_VALUEThrown when a @nhtio/adk!Retrievable is initialised with a value that fails schema validation.
E_INVALID_INITIAL_THOUGHT_VALUEThrown when a @nhtio/adk!Thought is initialised with a value that fails schema validation.
E_INVALID_INITIAL_TOOL_CALL_VALUEThrown when a @nhtio/adk!ToolCall is initialised with a value that fails schema validation.
E_NO_READER_RESOLVERThrown when decode()-ing a reader handle whose tag has no registered resolver.
E_READER_NOT_DESCRIBABLEThrown when encode()-ing a reader-backed primitive (@nhtio/adk!Media, @nhtio/adk!SpooledArtifact) whose underlying reader cannot describe itself.
E_TOKENIZABLE_EVALUATOR_INVALIDThrown by @nhtio/adk!Tokenizable when a DYNAMIC (evaluatable) value's evaluator function fails to produce a usable string at resolve time — either it THREW, or it RETURNED A NON-STRING.

Tools ​

Exceptions from tool construction, registration, argument validation, and handler execution. E_TOOL_DOWNSTREAM_ERROR wraps handler throws — the original error is on .cause.

VariableDescription
E_INVALID_INITIAL_TOOL_VALUEThrown when a @nhtio/adk!Tool is constructed with a value that fails schema validation.
E_INVALID_TOOL_ARGSThrown synchronously when @nhtio/adk!Tool.validate is called with arguments that fail the tool's input schema.
E_TOOL_ALREADY_REGISTEREDThrown when @nhtio/adk!ToolRegistry.register is called for a tool name that is already registered and overwrite is not true.
E_TOOL_DOWNSTREAM_ERRORThrown (as a rejection reason) when a @nhtio/adk!Tool's handler throws during execution.

Turn Input Validation ​

Exceptions thrown when the raw turn context supplied to runner.run() fails validation. Fatal and synchronous — thrown before turnStart is emitted.

VariableDescription
E_INVALID_TURN_CONTEXTThrown by @nhtio/adk!TurnRunner when the @nhtio/adk!TurnContext supplied to run fails schema validation.

Turn Runner Construction ​

Exceptions thrown when a @nhtio/adk!TurnRunner is misconfigured at construction time. Fatal — a misconfigured runner cannot execute turns.

VariableDescription
E_INVALID_TURN_RUNNER_CONFIGThrown by @nhtio/adk!TurnRunner when the supplied config object fails schema validation at construction time.