try {
await deploy();
} catch (error) {
return out.fail(error);
}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.
Exit codes
Section titled "Exit codes"0
ok1
failed: an error diagnostic, or aconfig or runtime failure2
change the command: ausage failure, such as a bad --format, or action_requiredA tool keeps 3 and up for its own codes.
Each format
Section titled "Each format"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>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>--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>"
}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.
Your own failures
Section titled "Your own failures"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" }]);failure builds a usage, config, runtime or action_required failure. actionRequired builds the last one, with what is missing.