You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(claude): add terse vs verbose balance to ERROR MESSAGES
Splits the doctrine into three audience tiers so contributors do
not bloat library-API errors when the same four ingredients apply
at different verbosity levels:
- Library-API errors (caller-facing): terse, four ingredients may
collapse into one line. Messages get asserted on in consumer
tests — short + stable matters.
- Validator/config errors (build-time): verbose, each ingredient
spelled out. The reader is in a file looking for the record.
- Programmatic errors (internal assertions): terse, rule only.
Adds a bloat test — if removing a word loses information keep it,
if it only loses rhythm drop it. Counter-example shows a bloated
library error that restates the rule three times versus the
ingredient-complete terse version.
Mirrored to socket-repo-template.
Copy file name to clipboardExpand all lines: CLAUDE.md
+21-6Lines changed: 21 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,23 +90,38 @@ The umbrella rule: never run a git command that mutates state belonging to a pat
90
90
91
91
## ERROR MESSAGES
92
92
93
-
Errors are a UX surface. When validating config or enforcing invariants, every error message must let the reader fix the problem without reading the source. Four ingredients, in order:
93
+
Errors are a UX surface. Every error message must let the reader fix the problem without reading the source. Four ingredients, in order:
94
94
95
95
1.**What**: the rule that was violated (the contract, not the symptom)
96
96
2.**Where**: the exact file, key, line, or record — never "somewhere in config"
97
97
3.**Saw vs. wanted**: the offending value and the allowed shape/set
98
98
4.**Fix**: one concrete action to resolve it
99
99
100
-
- Write the fix step in the imperative (`add "filename" to part 3`), not passive narration (`"filename" was missing`)
101
-
- Never say "invalid" without what made it invalid. `invalid filename 'My Part'` is a symptom; `filename 'My Part' must be [a-z]+ (lowercase, no spaces)` is a rule
102
-
- If two records collide, name both — not just the second one found
103
-
- Suggest, don't auto-correct. An error that silently repairs state hides the bug in the next run
100
+
Find the balance between terse and meaningful — meaningful does not mean bloated:
104
101
105
-
Example — validator on `tour.json`:
102
+
-**Library-API errors** (thrown from the published package to its callers): terse. A caller catching and asserting on the message needs it short and stable. The four ingredients may collapse into one line; `name "__proto__" cannot start with an underscore` carries all four (what = start-rule, where = name component, saw = `__proto__`, fix implied by the rule).
103
+
-**Validator / config errors** (build-time, developer-facing): verbose. The reader is staring at a file, needs to find the offending record, and won't re-run the tool to spot the next hit. Every ingredient gets its own words.
104
+
-**Programmatic errors** (internal assertions, invariant checks): terse, rule-only. No caller will parse the message; terse keeps the check readable.
105
+
106
+
Baseline rules that apply to all three:
107
+
108
+
- Write the fix step in the imperative (`add "filename" to part 3`), not passive narration (`"filename" was missing`).
109
+
- Never say "invalid" without what made it invalid. `invalid filename 'My Part'` is a symptom; `filename 'My Part' must be [a-z]+ (lowercase, no spaces)` is a rule.
110
+
- If two records collide, name both — not just the second one found.
111
+
- Suggest, don't auto-correct. An error that silently repairs state hides the bug in the next run.
112
+
- Bloat test: if removing a word loses information, keep it. If removing it loses only rhythm, drop it.
113
+
114
+
Example — validator on `tour.json` (verbose form, one record per run):
106
115
107
116
- ✗ `Error: invalid tour config`
108
117
- ✓ `tour.json: part 3 ("Parsing & Normalization") is missing "filename". Add a single-word lowercase filename (e.g. "parsing") to this part — one per part is required to route /<slug>/part/3 at publish time.`
109
118
119
+
Example — library API error (terse form, caught in user code):
120
+
121
+
- ✗ `Error: invalid component` (misses what / saw)
122
+
- ✗ `The "name" component of type "npm" failed validation because the provided value "" is empty, which is not allowed because names are required; please provide a non-empty name.` (bloated — restates the rule three times)
123
+
- ✓ `npm "name" component is a required component` (rule + where + implicit saw=missing)
0 commit comments