GitHub
Skip to content

Failures

The exit codes readerly uses, and how a failure reads at a terminal, for an agent, and in JSON and jsonl.
try {
  await deploy();
} catch (error) {
  return out.fail(error);
}
ts

out.fail renders the failure for the reader and returns its exit code. An error from readerly keeps its kind and fix. Anything else thrown is a runtime failure.

0

ok

1

failed: an error diagnostic, or a config or runtime failure

2

change the command: a usage failure, such as a bad --format, or action_required

A tool keeps 3 and up for its own codes.

An action_required failure from acme deploy --prod, for each reader:

Terminal (stderr)
✖ Account is required.
├▶ fix: Pass --account.
├▶ missing: --account (ACME_ACCOUNT), one of personal, team
╰▶ rerun: acme deploy --prod --account <account>
txt
Agent
acme deploy: action required. Account is required.
fix: Pass --account.
missing: --account (ACME_ACCOUNT), one of personal, team
rerun: acme deploy --prod --account <account>
txt
--format json
{
  "schema": "acme.deploy/v1",
  "status": "action_required",
  "error": { "code": "ACME_INPUT", "fix": "Pass --account.", "message": "Account is required." },
  "missing": [
    { "field": "account", "flag": "--account", "env": "ACME_ACCOUNT", "choices": ["personal", "team"] }
  ],
  "rerun": "acme deploy --prod --account <account>"
}
json

In text, the failure goes to stderr and stdout stays empty. An agent reads it on stdout, verdict first. JSON keeps it on stdout, in one document a parser can always read. jsonl writes a version, an error and a result record.

import { actionRequired, failure, FailureError } from "readerly/envelope";

throw new FailureError(failure("config", "acme.config.ts has no entry.", { fix: "Add an entry." }));

throw actionRequired("Account is required.", [{ field: "account", flag: "--account" }]);
ts

failure builds a usage, config, runtime or action_required failure. actionRequired builds the last one, with what is missing.