@nhtio/adk/batteries/llm/ollama/exceptions
Battery-scoped exception constructors for the native Ollama /api/chat adapter.
Remarks
Battery-scoped exception classes for the native Ollama adapter. These exceptions are owned by the battery (not the ADK core) and are minted via createException from @nhtio/adk/factories. Re-exported from the battery's barrel. They mirror the OpenAI Chat Completions battery's exception set (same status codes, same fatal/non-fatal split) with two deliberate divergences:
E_OLLAMA_INVALID_TOOL_CALL_ARGS— native/api/chatreturns tool-callargumentsas a JSON object, not a string, so there is noJSON.parsefailure path. This fires only when theargumentsvalue is present but is not a plain object (array / null / primitive — defensive against a non-conformant server or proxy).E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY— native/api/chatsupports only base64images[], so its "unsupported" set is wider than the OpenAI battery's (audio, document, and video all fall through here underunsupportedMediaPolicy: 'throw').
Malformed NDJSON lines are NOT a distinct exception — they are swallowed and surfaced via helpers.log.trace (matching the OpenAI battery's sse-parse-failure policy); only a transport throw mid-stream raises E_OLLAMA_STREAM_ERROR.
Variables
| Variable | Description |
|---|---|
| E_INVALID_OLLAMA_OPTIONS | Thrown when the resolved adapter options (constructor, executor overrides, or per-dispatch stash.ollama) fail validation against ollamaOptionsSchema. |
| E_OLLAMA_CONTEXT_OVERFLOW | Thrown when the total token weight of the resolved request exceeds contextWindow. Only raised when tokenEncoding is non-null. Carries { total, contextWindow, tokenEncoding, perBucket } in the message so middleware can target shedding. |
| E_OLLAMA_HTTP_ERROR | Thrown when the upstream /api/chat endpoint returns a non-2xx response. Non-fatal — surfaced via ctx.nack(...) so middleware can decide retry / fail. |
| E_OLLAMA_INVALID_TOOL_CALL_ARGS | Raised when a tool-call's arguments value emitted by the model is present but is not a JSON object (e.g. an array, null, or a primitive). |
| E_OLLAMA_REQUEST_TIMEOUT | Thrown when the initial request handshake (TCP connect, TLS, response headers) does not complete before requestTimeoutMs. Non-fatal — surfaced via ctx.nack(...). Eligible for retry on the same footing as a retriable 5xx. |
| E_OLLAMA_STREAM_ERROR | Thrown when the NDJSON stream emits a transport-level failure mid-stream (the reader throws). Non-fatal — surfaced via ctx.nack(...). A single malformed NDJSON line is NOT this error — it is swallowed + logged at trace. |
| E_OLLAMA_STREAM_STALLED | Thrown when the NDJSON stream goes silent for longer than streamIdleTimeoutMs. Non-fatal — surfaced via ctx.nack(...) so middleware can recover. |
| E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY | Raised when a @nhtio/adk!Media instance whose modality cannot be natively represented in the Ollama /api/chat wire format reaches the adapter under unsupportedMediaPolicy: 'throw'. |