Skip to content

feat: hint at Notecard error and status code meanings#74

Open
Bucknalla wants to merge 1 commit into
masterfrom
alex-error-code-hints
Open

feat: hint at Notecard error and status code meanings#74
Bucknalla wants to merge 1 commit into
masterfrom
alex-error-code-hints

Conversation

@Bucknalla

@Bucknalla Bucknalla commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

What

When you run a request against a Notecard, the CLI now prints a human-readable hint explaining any recognized {code} in the output, using the definitions from notecard.codes.json.

It fires in two places:

  • Errors — e.g. a failed -req whose err contains {template-incompatible}
  • Status codes in successful responses — e.g. hub.status returning {connected}{cell-registered}
$ notecard -req '{"req":"hub.status"}'
{"status":"{connected}{cell-registered}"}
hint: {connected} Notecard is connected to the cellular network.
hint: {cell-registered} Wireless service successfully registered.

Source of definitions — fetched, not embedded

notecard.codes.json is fetched through the same fetch-and-cache pipeline used for schema validation (loadOrFetchSchema/tmp/notecard-schema/), not committed to this repo. The codes URL is derived from the API schema's own $ref base, so:

  • It's pulled from the exact same release the API schema points at (the release's notecard.api.json pins its $refs to a tagged version, e.g. refs/tags/v1.3.1) — version-pinned, no drift.
  • It automatically follows any NOTE_JSON_SCHEMA_URL override.
  • There is no maintained copy in this repo to keep in sync.

If the codes file can't be fetched (offline with a cold cache), hints are simply unavailable — the same network/cache tradeoff the existing validation code already makes.

Why token-scanning rather than driving hints off response-schema validation: only 2 of ~75 .rsp. schemas (hub.status, hub.sync.status) enumerate codes, and the err field isn't modeled with code enums anywhere. Scanning {tokens} in the response/error against the fetched codes file gives full coverage across all request types. (If you want response schema validation as its own feature, that's a separate change.)

Behavior

  • Hints go to stderr so JSON on stdout stays clean and pipeable.
  • Color auto-disables on non-TTY (fatih/color, already a dependency).
  • Unknown/undocumented tokens are silently skipped — zero noise.
  • On by default; suppress with the new -nohints flag (grouped under "Communication & Debug" in -h).

Known upstream gap

The upstream codes file covers status codes richly but omits several common error qualifiers note-go defines — {io}, {timeout}, {not-supported}, {syntax}. Tracked in blues/notecard-schema#305; once merged, hints pick them up automatically with no CLI change.

Tests

  • notecard/codes_test.go — hermetic unit tests for parseCodeDescriptions (incl. malformed input) and explainCodesWith (multi-token, dedup, undocumented-skip, status-in-response, empty).
  • Verified live against the real schema release: URL derivation → fetch → cache → hint, with documented codes hinting and {io} correctly skipped; stdout stays clean JSON. go build / go vet / go test all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_018ngtas2Zmb7rFBd6y2hV8Y

Print a human-readable hint whenever a Notecard request returns, or a
successful response contains, a recognized {code}.

Definitions come from notecard.codes.json (blues/notecard-schema),
fetched through the same fetch-and-cache pipeline used for schema
validation rather than embedded. The codes URL is derived from the API
schema's own $ref base, so it is pulled from the exact same release the
API schema points at (version-pinned, no drift) and follows any
NOTE_JSON_SCHEMA_URL override. Nothing is committed to this repo.

Hints are written to stderr so JSON on stdout stays clean, color
auto-disables on non-TTY, and unrecognized tokens are skipped silently.
On by default; suppress with -nohints. If the codes file cannot be
fetched (offline, cold cache) hints are simply unavailable.

Note: the upstream codes file omits common error qualifiers
({io}, {timeout}, {not-supported}, {syntax}, ...); tracked in
blues/notecard-schema#305.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ngtas2Zmb7rFBd6y2hV8Y
@Bucknalla Bucknalla force-pushed the alex-error-code-hints branch from f0b64b4 to bf94db0 Compare July 7, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant