Output Envelope and Exit Codes
The one JSON shape every Mode 8 surface returns, the error types and the process exit codes.
Mode 8 answers in one shape everywhere: the CLI, the MCP server and the Studio HTTP API all return a JSON object with "ok": true or "ok": false. Scripts and agents branch on ok, then on error.type, and never have to parse human text. This page is the full contract for that shape.
Note
This page is generated from mode8 schema and real CLI runs by docs/manual/_tools/gen_reference.py. To change it, change Mode 8 (or the prose in the generator) and run the generator with --write; a test fails when this page is out of date.
Success#
A successful command prints {"ok": true} plus its report keys. A real run:
$ mode8 draft knight_right --out knight.png
{"ok": true, "out": "knight.png", "archetype": "knight_right", "size": [64, 72]}It exits 0. Commands that check something (lint, verify, doctor and friends) also report a top-level pass. ok: true with pass: false means "the command worked, and the check failed": that is exit code 1, not an error.
A failure inside a successful report (a doctor probe, a job, a generation candidate) is reported as "failure": {"type", "msg"} (or null), never as error. The error key only ever holds the envelope below.
Errors#
Every error on every surface looks like this:
{"ok": false, "error": {"type": "<exception class name>", "msg": "<message>"}}type is the error class name and msg is a human message. Some types add extra keys inside error. A missing input file:
$ mode8 lint missing.png
{"ok": false, "error": {"type": "NotFoundError", "msg": "sprite not found: missing.png", "path": "missing.png", "hint": "the current folder has no missing.png"}}That one exits 2. An out-of-range value names the offending parameter in error.param:
$ mode8 draft knight_right --out big.png --size 2000x2000
{"ok": false, "error": {"type": "InputError", "msg": "size sides must be within 1..1024, got 2000x2000", "param": "size", "hint": "example: mode8 draft knight_right --out drafts/hero.png"}}That one exits 2.
- Messages and string extras are clipped to 1000 characters, and a value echoed inside a message to 200, so an error never mirrors a huge input back.
- MCP results also carry
"tool": "<tool name>"next took. - A command-line usage error (unknown flag, invalid choice) is a
UsageErrorwith an extrausageline; the human message also goes to stderr. - Branch on
typeand the documented extras. Themsgwording may change in any release.
Error types#
| Type | CLI exit | Studio HTTP | Meaning | Extras |
|---|---|---|---|---|
UsageError | 2 | - | invalid command line (argparse); the CLI also prints error.usage | |
InputError | 2 | 400 | an invalid user-supplied value; error.param names the parameter when known | param (the offending parameter, when known), suggestions (close matches for a mistyped name, flag or choice, best first), hint (what to do next, one sentence), fields (Studio: the unknown request-body field names), any keyword extras, e.g. path, conflicts for a mode8 init config conflict |
NotFoundError | 2 | 404 | a named file, project, asset, layer, job or palette does not exist (an InputError) | path (a missing file / directory) or asset / layer_id / job_id |
NothingToUndoError | 2 | 400 | undo with nothing to undo (an InputError) | asset, can_undo, can_redo |
NothingToRedoError | 2 | 400 | redo with nothing to redo (an InputError) | asset, can_undo, can_redo |
AssetExistsError | 2 | 409 | creating or importing an asset whose name is already taken (an InputError, also a Python FileExistsError) | asset, path (the project-relative asset directory) |
ConflictError | 3 | 409 | optimistic-concurrency failure: the file changed since it was read | conflict, path, expected_sha256, actual_sha256 |
LayeredAssetError | 3 | 409 | a flat-master write on an asset with a layer stack | layered, asset, layer_count, hint (MCP only: how to proceed) |
ProjectVersionError | 3 | 409 | mode8.toml declares a newer (or invalid) project format | path, project_version, supported_version |
BackendError | 3 | 500 | ComfyUI is unreachable or stopped answering before any candidate finished (mode8 gen / inpaint / cast, mode8_gen; a Studio job reports it as its failure); the hint says how to start it again | hint (what to do next), start_command (how to start ComfyUI), log_path (MODE8_COMFY_LOG, when set) |
UnknownToolError | - | - | MCP only: the tool name does not exist | |
| any other exception class | 3 | 500 | a runtime / backend failure (IO, ComfyUI, unexpected); never a traceback |
NotFoundError, AssetExistsError, NothingToUndoError and NothingToRedoError are subclasses of InputError, so code that handles InputError handles them too. Studio adds a few HTTP-only types (AuthError, ForbiddenError, PayloadTooLargeError, ...), listed on Studio HTTP API.
Exit codes#
The CLI's exit code tells you what kind of outcome you got before you read a byte of stdout. They are mode8.exitcodes (OK, CHECK_FAILED, USAGE, RUNTIME):
| Code | Name | Meaning |
|---|---|---|
0 | OK | The command succeeded (and every check it reports passed); stdout holds its JSON report with "ok": true. |
1 | CHECK_FAILED | The command ran but a check it reports failed (lint, quality-strict, verify, doctor, gen, inpaint, cast, autotile, ui lint, starter lint, setup download); stdout holds the full JSON report, whose top-level "pass" is false. |
2 | USAGE | Bad input. Either an invalid command line (argparse usage error; nothing ran): stdout holds {"ok": false, "error": {"type": "UsageError", "msg", "usage"}} and the human message goes to stderr; or an invalid user-supplied value (format, palette, name, size, margins, color, scale, pixels_per_unit, emissive token, template, kind / style, fps, conflicting options, init config conflict, malformed JSON input file): stdout holds {"ok": false, "error": {"type": "InputError", "msg", ...}}; a missing input path, project, asset or layer is the InputError subclass NotFoundError ({"type": "NotFoundError", "msg", "path"?}). |
3 | RUNTIME | A runtime or backend error (IO, ComfyUI, ConflictError, ProjectVersionError, LayeredAssetError, unexpected exceptions); stdout holds {"ok": false, "error": {"type", "msg", ...}}. Also used when stdout is closed early (e.g. mode8 ... | head): output stops silently, with no traceback. |
Reacting to an outcome#
A small decision table for scripts and agents:
| You see | Do this |
|---|---|
exit 0 | Carry on. |
exit 1, "pass": false | Read the report (errors, issues, failed_assets, hints), fix the art or the environment, then run again. Retrying unchanged gives the same answer. |
exit 2 | Fix the input: error.param, error.path, error.asset or error.layer_id point at it. Retrying unchanged gives the same answer. |
exit 2, AssetExistsError | The asset name is taken. Pick another name, or edit the existing asset instead of creating it again. |
exit 3, ConflictError | Someone else changed the file. Re-read it, redo your edit on the new pixels, and write again with the new expected_sha256. |
exit 3, ProjectVersionError | The project was written by a newer Mode 8. Upgrade Mode 8; do not edit the version in mode8.toml. |
exit 3, other types | A runtime or backend failure (ComfyUI down, disk full, ...). Read msg; retry only if the cause was transient. |
In a shell script, the exit code is all you need for a first decision:
if mode8 lint hero.png --palette nes_crimson_hero > lint.json; then
echo "clean"
else
echo "lint exited $?"
fiSee also#
- Troubleshooting for real error messages and their fixes.
- CLI Reference for the exit codes of each command.
- Agents and MCP for how agents should react to each outcome.