Manual Reference

On this page
  1. Success
  2. Errors
  3. Error types
  4. Exit codes
  5. Reacting to an outcome
  6. See also

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:

terminal
$ 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:

json
{"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:

terminal
$ 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:

terminal
$ 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 to ok.
  • A command-line usage error (unknown flag, invalid choice) is a UsageError with an extra usage line; the human message also goes to stderr.
  • Branch on type and the documented extras. The msg wording may change in any release.

Error types#

TypeCLI exitStudio HTTPMeaningExtras
UsageError2-invalid command line (argparse); the CLI also prints error.usage
InputError2400an invalid user-supplied value; error.param names the parameter when knownparam (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
NotFoundError2404a named file, project, asset, layer, job or palette does not exist (an InputError)path (a missing file / directory) or asset / layer_id / job_id
NothingToUndoError2400undo with nothing to undo (an InputError)asset, can_undo, can_redo
NothingToRedoError2400redo with nothing to redo (an InputError)asset, can_undo, can_redo
AssetExistsError2409creating or importing an asset whose name is already taken (an InputError, also a Python FileExistsError)asset, path (the project-relative asset directory)
ConflictError3409optimistic-concurrency failure: the file changed since it was readconflict, path, expected_sha256, actual_sha256
LayeredAssetError3409a flat-master write on an asset with a layer stacklayered, asset, layer_count, hint (MCP only: how to proceed)
ProjectVersionError3409mode8.toml declares a newer (or invalid) project formatpath, project_version, supported_version
BackendError3500ComfyUI 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 againhint (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 class3500a 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):

CodeNameMeaning
0OKThe command succeeded (and every check it reports passed); stdout holds its JSON report with "ok": true.
1CHECK_FAILEDThe 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.
2USAGEBad 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"?}).
3RUNTIMEA 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 seeDo this
exit 0Carry on.
exit 1, "pass": falseRead the report (errors, issues, failed_assets, hints), fix the art or the environment, then run again. Retrying unchanged gives the same answer.
exit 2Fix the input: error.param, error.path, error.asset or error.layer_id point at it. Retrying unchanged gives the same answer.
exit 2, AssetExistsErrorThe asset name is taken. Pick another name, or edit the existing asset instead of creating it again.
exit 3, ConflictErrorSomeone else changed the file. Re-read it, redo your edit on the new pixels, and write again with the new expected_sha256.
exit 3, ProjectVersionErrorThe project was written by a newer Mode 8. Upgrade Mode 8; do not edit the version in mode8.toml.
exit 3, other typesA 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:

bash
if mode8 lint hero.png --palette nes_crimson_hero > lint.json; then
  echo "clean"
else
  echo "lint exited $?"
fi

See also#