Errors and exit codes¶
Exit codes¶
| Exit code | Meaning |
|---|---|
| 0 | Success (status:"ok"). run returns 0 when it starts the child, including when the child fails or times out; exceeding --grep-limit returns 3 with status:"partial". The child's own code is in exit_code. |
| 1 | General error: bad arguments, missing input, boundary violation, I/O failure, lock timeout, syntax error. |
| 2 | A precondition did not hold: a selector matched nothing or more than one place, a count or hash guard did not match, or the target changed before tx commit or undo. |
| 3 | A read was cut at a limit (status:"partial"). The output is a success, not an error, and carries no error.code. Writes never return 3. |
src/dispatch.lisp maps a command result to these codes: :ok to 0,
:partial to 3, and an error to the exit code its error.code has in the
catalog below.
The error envelope¶
Every error is one JSON object on standard error:
{"schema_version":2,"status":"error","command":"edit",
"error":{"code":"selection.ambiguous","message":"...","exit_code":2,
"repairs":[{"action":"read","detail":"...","command":"aitools read dup.txt"}],
"candidates":[{"line":1,"text":"x"},{"line":2,"text":"x"}]}}
repairsalways has at least one entry.make-error-envelope(packages/core/protocol/src/domain/envelope.lisp) signals an internal error rather than build an envelope without one.repairs[].commandsuggests an aitools invocation. It is not run automatically. Some repairs name only the command to use (aitools readforcat), not a complete invocation.candidates,diagnostics, andconflictsappear only when the error has them.- When no command-specific repair applies, the repair is
aitools schema <command>.
See JSON output for the field-by-field shape.
error.code catalog¶
The catalog lives in data/domain/protocol/error-catalog-data.lisp
(aitools.data:*protocol-error-codes*); error-code-exit-code in
packages/core/protocol/src/domain/error-catalog.lisp reads it. The table
below is generated from that data and from the error codes each command
schema declares.
"Declared by" lists only the commands whose own schema names the code.
Three codes can also come from the composition root for any command, whether
or not its schema declares them:
argument.invalid for usage errors and --lock-timeout values that are
not durations, environment.busy when recovery cannot take the workspace
lock, and internal.unexpected for an uncaught condition
(src/dispatch.lisp).
When each code occurs¶
| error.code | Occurs when |
|---|---|
argument.invalid |
Argument parsing fails, a value has the wrong type or range, options that exclude each other are combined, or a required guard or input is missing. It also covers chmod --mode setting a setuid, setgid, or sticky bit, an invalid date for touch --mtime, a non-numeric table agg column, and unknown command names. org query uses it for an invalid or non-minute-aligned --at, an unknown --tz, or an unsupported --dst-policy. Malformed --range and non-ASCII digits in numeric options are invalid too. |
input.not-found |
A file, symbol, JSON Pointer, archive entry, op, tx, bg process, or snapshot does not exist (a true ENOENT). Commands may include candidates for missing files or entries. A file that exists but cannot be read is environment.io, not this code. |
input.not-utf8 |
A text edit, Org read, or Markdown headings/read/replace command receives bytes that are not valid UTF-8. |
input.unsupported-format |
A file is not in a format the command handles (doc, table, archive, check), an encoding is unsupported, an Org read receives binary input or NUL bytes, org export encounters unsupported syntax or a file, ID, or internal link, or an md command receives binary input. |
input.unsupported-language |
The code group, --symbol, or transform --op comment meets a language outside the pattern table. |
input.syntax-error |
check finds a syntax error; a regular expression, diff, Org document, or Org match expression is malformed; a regex exceeds its step limit; a value does not parse (util decode, util calc, time convert); transcode meets bytes it cannot decode; or an md command cannot parse its input. Structured-document reads and writes use this for malformed input; doc set --stdin, doc merge --stdin, and doc patch --stdin use it for malformed JSON. TOML integer range errors use it too. Org parse and match errors include source diagnostics. |
input.unsupported-value |
A YAML or TOML doc read or write encounters a value outside the JSON subset, such as a custom YAML tag, a cyclic alias, duplicate or non-string mapping keys, multiple YAML documents, or a non-finite float. |
selection.no-match |
A selector matches nothing, an apply hunk does not fit, or a JSON Patch test fails. When a command can suggest alternatives, it includes them in candidates; the entries depend on the command. |
selection.ambiguous |
A selector that must be unique matches more than once. The matches come as candidates. |
selection.count-mismatch |
--expect-count differs from the actual count. |
refusal.target-changed |
--expect-hash differs, or the target changed before tx commit, tx rebase, or undo. The paths come as conflicts. |
refusal.redacted-input |
A write's input contains the literal text [REDACTED_SECRET]. |
refusal.outside-workspace |
A write would land outside the workspace root, through a symlink that leaves it, or inside the workspace's .git/ (its resolved git directory and common directory). archive extract entry paths and copy --recursive children are routed through the same boundary, so a .git/ entry or nested .git/ is refused. rm also refuses the workspace root, home directory, and paths with .git or .jj components. org agenda and org query use this code when an explicit path resolves outside the workspace. The state directory lives outside the root, so writes there are refused as outside-workspace too. |
refusal.exists |
The destination exists and overwriting was not allowed. |
refusal.not-a-file |
A file-only operation targets a directory, a read targets a FIFO, socket, or device, a text edit targets a binary file, rm targets a non-empty directory, or chmod/touch targets a hard-linked file (link count > 1). The repair command varies by operation. |
refusal.too-large |
Archive operations or copy --recursive exceed their size or entry limit, an Org document exceeds the parser limit, an md input exceeds 16 MiB, or an envelope would exceed the JSON writer's output limit. The output-limit repair is aitools schema <command>; reduce the requested output with a limit or narrower selector. |
environment.io |
A read or write fails, including a permission-denied (EACCES) read of an existing file. read, info, check, diff, Org read commands, and write --content-file report this rather than input.not-found. A failed rename names the blocking destination. |
environment.busy |
The workspace lock is not acquired within --lock-timeout. The repair repeats the same command. |
environment.timeout |
wait exceeds its requested deadline, or an HTTP request or OS name lookup exceeds the net command's total deadline. |
environment.unavailable |
A required executable cannot be started, or an OS facility is unavailable (for example, no source for sys ports). |
internal.unexpected |
An unexpected condition. The repair is aitools schema <command> when the command is known. |
Unknown command names¶
A name that is not a registered command returns argument.invalid, exit
code 1. src/dispatch-names.lisp chooses the repairs by the kind of name, in
this order:
- A bare group name (
doc,bg,tx) is a real command node with no handler, so the message is<group> requires a subcommandand the repair isaitools schema <group>. That repair is runnable:aitools schemalists a group's subcommands when given the group name (%group-schemasinsrc/schema.lisp), so it no longer fails withinput.not-found. - A retired document command name (
json.get,yaml.get, ortoml.get; tokenized input such asjson get) is resolved through its correspondence-table entry and returns the currentdoccommand's repair. These names are not registered command aliases. - A shell name in the correspondence table (
cat,grep,uuid) returns that row's repairs, drawn fromaitools.data:*correspondence-table*and shown in Using aitools from an agent. - A group subcommand typed without its group (
get,status,logs) returns onerun-insteadrepair per group whose subcommand list holds that name, each the grouped form of the invocation with the group token inserted and the globals and operands kept. This is driven by the live registry (%group-subcommand-repairsinsrc/dispatch-names.lisp), not by the correspondence table, sostatusreturnsaitools bg statusandaitools tx status. - Any other name gets the repair
aitools schema.
$ aitools cat hello.lisp
{"schema_version":2,"status":"error","command":"cat","error":{"code":"argument.invalid","message":"unknown command cat","exit_code":1,"repairs":[{"action":"run-instead","detail":"Read a file with line numbers and range control.","command":"aitools read"}]}}
$ aitools uuid
{"schema_version":2,"status":"error","command":"uuid","error":{"code":"argument.invalid","message":"unknown command uuid","exit_code":1,"repairs":[{"action":"run-instead","detail":"`uuid` is a group subcommand name; the group prefix is required.","command":"aitools util uuid"}]}}
schema also reports near-miss candidates as an agent types them (doc get,
not the dotted dispatch name doc.get); %typed-name in src/schema.lisp
builds them from the command schemas.