Skip to content
2 min read · 422 words

@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/chat returns tool-call arguments as a JSON object, not a string, so there is no JSON.parse failure path. This fires only when the arguments value 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/chat supports only base64 images[], so its "unsupported" set is wider than the OpenAI battery's (audio, document, and video all fall through here under unsupportedMediaPolicy: '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

VariableDescription
E_INVALID_OLLAMA_OPTIONSThrown when the resolved adapter options (constructor, executor overrides, or per-dispatch stash.ollama) fail validation against ollamaOptionsSchema.
E_OLLAMA_CONTEXT_OVERFLOWThrown 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_ERRORThrown 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_ARGSRaised 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_TIMEOUTThrown 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_ERRORThrown 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_STALLEDThrown when the NDJSON stream goes silent for longer than streamIdleTimeoutMs. Non-fatal — surfaced via ctx.nack(...) so middleware can recover.
E_OLLAMA_UNSUPPORTED_MEDIA_MODALITYRaised 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'.