Core

Errors

ViewportError, SpecError and the stable codes core raises.

Outcomes are values, failures are exceptions. A failed match, an over-budget run or an undecidable condition is a result you inspect. An exception means the input was invalid or the world broke.

  • ViewportError(code, message, details) is the base of every Viewport error. code is stable API (<package>.<snake_reason>); docs_url / docsUrl points at https://docs.getviewport.com/errors/<code>. In TypeScript, instanceof works even when two copies of core are loaded.
  • SpecError is a ViewportError for invalid authored documents. It carries every SpecIssue (path, code, message, suggestion, file, line, column) and formats them as file:line:column path: message. Did you mean "x"?.
CodeRaised by
core.spec_invalidschema validation (parse)
core.matcher_invalidcompile_matcher / compileMatcher, parse("matcher/v1", ...)
core.invariant_invalidparseInvariants / parse_invariants (@viewportai/core/invariants, viewportai.core.invariants)
core.matcher_asyncsync match on a spec that uses judge
core.judge_unavailableamatch / matchAsync with no judge for the requested name
core.yaml_invalidload_yaml / loadYaml
core.path_invalidparse_path / parsePath, query_path / queryPath
core.duration_invalidparse_duration / parseDuration
core.json_invalidstable_json / stableJson on NaN, Infinity or non-JSON values
core.canonical_json_invalidcanonical_json / canonicalJson (floats, unsafe integers, non snake_case keys)
core.jcs_invalidjcs / jcsDigest (NaN, Infinity, lone surrogates)
core.tool_args_invalida tool whose arguments fail its schema
core.tool_args_unstablevalidating a call's approved view again would change it (a non-idempotent transform); what a gate approves must be what runs
core.tool_schema_invaliddefining a tool whose JSON Schema input_schema core cannot run
core.tool_server_invalida tool server answering anything but { result }, { error: { type, message } } or nothing
core.mask_too_latecall.mask(...) called after next(): the call's start event already holds its arguments
core.tool_sync_in_loop(Python) a plain def @tool called synchronously while a middleware on it waits on the event loop (tool_middleware(loop_bound=True), or one that waited before the body ran); use await tool.execute(...) on that loop
core.redact_key_invalidVIEWPORT_REDACT_KEY or decodeRedactKey / decode_redact_key given a malformed or weak key
core.fake_exhausteda fake_tool / fakeTool called more times than it has responses

Issue codes inside SpecError (unknown_key, required, type, mixed_keys, suspicious_key, operator_not_allowed, regex_invalid, duplicate_key, ...) are stable too, and conformance vectors pin them.