0035 — One error model with stable reason codes
Status: accepted
Problem
The CLI already sorted every failure into one of five classes (policy, usage, data, parse, internal) with
fixed exit codes. Beneath that, about twenty ad-hoc Error subclasses were mapped to a class one call site at a time,
and the MCP server reported a failure as a bare message. A caller could not tell two usage failures apart without
parsing prose, and an MCP client could not branch on a failure at all.
Decision
src/evergreen-error.tsowns the model:EXIT_CODES, theERROR_CODEStable of stable reason codes (each belongs to exactly one class), andEvergreenError, which carries one reason code. Domain errors extend it, so the class and exit code follow from the code.- The CLI top-level handler and
ctx.failErrormap anEvergreenErrorto its class and exit code. A thrown value that is not anEvergreenErrorisinternal. evergreen.error.v1gains anerror.reasonfield holding the reason code.error.code(the class) anderror.exitCodeare unchanged, so existing callers keep working.- An MCP tool failure keeps its text and
isErrorflag and adds_meta.evergreenwithcode,class, andexitCode. It still carries no structured content. - Reason codes are never renamed or moved to another class. A new failure gets a new code.
Alternatives rejected
- Renaming
error.codeto the specific reason. It would break every script that branches on the class. - Structured content on MCP failures. The tool output schemas describe success; a failure document there would not validate against them.