Skip to content

chore(sdk): adopt Error Messages doctrine + error helpers (supersedes #612)#610

Open
John-David Dalton (jdalton) wants to merge 6 commits intomainfrom
chore/error-messages-doctrine
Open

chore(sdk): adopt Error Messages doctrine + error helpers (supersedes #612)#610
John-David Dalton (jdalton) wants to merge 6 commits intomainfrom
chore/error-messages-doctrine

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 22, 2026

Summary

Aligns socket-sdk-js with the fleet's Error Messages doctrine and wires up the @socketsecurity/lib/errors helpers so we stop re-inventing error-shape checks in each package.

Docs

  • Add ## ERROR MESSAGES to CLAUDE.md following the fleet doctrine from socket-repo-template, tuned for the SDK library context (shorter, more terse than CLI tier — SDK callers often match on message text).
  • Add docs/references/error-messages.md with cross-fleet worked examples, anti-patterns, and the rubric so CLAUDE.md stays tight.
  • Reference the joinAnd / joinOr helpers in the doctrine.

Error-helper adoption

  • Bump @socketsecurity/lib catalog pin 5.21 → 5.24 — 5.21's /errors subpath shipped CJS without named-export interop; 5.24 fixes it so import { errorMessage, isError, isErrnoException } from '@socketsecurity/lib/errors' resolves cleanly under ESM.
  • src/http-client.ts: switch e instanceof ErrorisError(e) in getResponseJson's JSON-parse catch (unified narrowing against the fleet helper).
  • src/file-upload.ts: replace e as NodeJS.ErrnoException unchecked cast with the isErrnoException(e) type guard. Same ENOENT/EACCES/EISDIR branch logic, but no more unchecked assertion.

Style (merged from #612, which this PR now supersedes)

  • Rename catch (err) / catch (error) identifiers to catch (e) fleet-wide.
  • Updates span src/http-client.ts plus the other error-handling sites that still used the older names.

Test plan

  • CLAUDE.md under 40 KB ceiling (~14.5 KB).
  • References doc self-contained and legible.
  • pnpm lint clean.
  • pnpm test — only failure is the worktree-directory brittleness in utils.test.mts (asserts against socket-sdk-js/package.json substring, my worktree is socket-sdk-js-errmsg). CI runs from socket-sdk-js and passes.
  • Re-verify confirm the CLAUDE.md section reads at junior-dev level (short declarative rules, terms defined inline).

Related

Add the fleet Error Messages section to CLAUDE.md, tuned for an SDK
library context:

- Four ingredients (What / Where / Saw vs. wanted / Fix).
- Audience tiers with emphasis on library API (terse, stable message
  text) since SDK errors are caught by callers who may match on them.
- Five baseline rules.
- Two short SDK-flavored examples (orgSlug required, AuthError shape).

Add `docs/references/error-messages.md` with cross-fleet worked
examples and anti-patterns so CLAUDE.md stays tight.
Point readers at @socketsecurity/lib/arrays' list-formatting helpers
from CLAUDE.md (one-line rule) and the worked-examples references doc
(new "Formatting lists of values" section).
- package.json: 5.21.0 → 5.24.0.
- src/http-client.ts: replace `e instanceof Error` check inside the
  JSON-parse fallback with `isError(e)` for cross-realm safety.
- docs/references/error-messages.md: pick up the new "Working with
  caught values" section from socket-repo-template.

Small codemod footprint — most of the SDK's error flow already runs
through the shared `ResponseError` / `APIError` classes rather than
raw `catch (e)`.

Pre-commit tests skipped (DISABLE_PRECOMMIT_TEST): the single failing
test (`resolveAbsPaths > should resolve array of relative paths to
absolute`) asserts a literal `"socket-sdk-js/package.json"` substring
which breaks in a `socket-sdk-js-errmsg` worktree — pre-existing
assumption, unrelated to this change. `pnpm run check` (lint + type)
passes clean.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 22, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​socketsecurity/​lib@​5.21.0 ⏵ 5.24.0100100100100100

View full report

Mechanical rename across 3 files (src/file-upload.ts, src/http-client.ts,
test/unit/http-client.test.mts) — 9 catch clauses converted. tsgo
--noEmit clean.
Replace the ad-hoc `e as NodeJS.ErrnoException` cast in file-upload.ts
with the @socketsecurity/lib/errors isErrnoException type guard. Same
runtime behavior — narrows e to NodeJS.ErrnoException only when the
value is genuinely an errno exception (Error subclass with a string
.code) — but removes an unchecked type assertion and matches the
error-helper adoption pattern elsewhere in this PR.
@jdalton John-David Dalton (jdalton) changed the title docs(claude): add Error Messages doctrine + references doc chore(sdk): adopt Error Messages doctrine + error helpers (supersedes #612) Apr 23, 2026
CLAUDE.md has a hard size ceiling and the Error Messages section had
drifted to 32 lines — duplicating content that already lives in
docs/references/error-messages.md. Slim CLAUDE.md to 11 lines: the
four-ingredient core, the SDK-tier stance (one sentence), and
pointers to the helpers + refs doc. Every rule / length tier / worked
example still has a home, just in the one place instead of two.

Move the two SDK-specific Examples (orgSlug required, 401 rejected)
into the refs doc's Library API errors table so nothing's lost.

Saves ~1 KB / 18 lines in CLAUDE.md.
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