fix(cli): make the API tolerate null options and context arguments - #4638
fix(cli): make the API tolerate null options and context arguments#4638josephfarina wants to merge 2 commits into
Conversation
Every exported API function used `options = {}` as a default parameter, which
only activates for `undefined` — passing explicit `null` bypassed it and threw
a raw `TypeError: Cannot read properties of null (reading 'cwd')` (or similar)
instead of a graceful `AstryxError`. This affected 17 of 19 API functions and
was the single largest robustness gap found by the chaos test (45 crashes total).
Add `options = options ?? {};` as the first statement in every affected function
body. This coalesces both `null` and `undefined` before any destructuring or
property access. The fix is one line per function — minimal, safe, and covers
the entire family at once.
Note: these crashes were all API-only (never reachable through the CLI, which
always passes commander's options object), so no end-user ever hit them — but
the programmatic API contract states 'never a raw crash' for any input.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The prior fix coalesced null options but left the trailing context object
({cwd}) on the three two-arg commands (init, upgrade, themeBuild) still
destructured with a bare default, so init({}, null) / upgrade({}, null) /
themeBuild(f, {}, null) still threw a raw 'Cannot read properties of null
(reading cwd)'. Normalize the context slot too (ctx = {} + ctx ?? {}).
Add api/null-options.test.mjs: a regression suite that drives every exported
API function with null in both the options and context slots and asserts none
throw a bare TypeError (AstryxError or success is fine). A coverage assertion
fails if a new export ships without a null-tolerance case, so the contract
can't silently regress. The suite runs from a throwaway temp cwd so init's
writes and core-resolution never touch the repo.
|
Closing — this change is unnecessary. The guards defended against callers passing an explicit The plain The other chaos-test fixes continue in #4639, now rebased directly onto #4637. |
Summary
Guards every exported API function against
nullin its optional arguments —the largest robustness gap the chaos test found. Stacked on #4637;
review/merge that first.
The bug
Every API function used
options = {}(and, on two-argument commands,{cwd = …} = {}) as a default parameter. JavaScript defaults only fire forundefined— passing an explicitnullbypassed them and threw a rawTypeError: Cannot read properties of null (reading 'cwd')(with no error codeand no
AstryxError) instead of a graceful error. This affected the wholepublic API surface: 17 functions on the
optionsargument, plus the trailingcontext argument on
init,upgrade, andthemeBuild.These are all shielded behind the CLI (Commander always passes a real object,
so no end user ever hit them) — but the programmatic API contract is "never a
raw crash for any input," which scripts and integrations rely on.
The fix
options = options ?? {}) as the firststatement in every affected function.
init,upgrade, andthemeBuild(an earlier pass fixed only theoptionsslot and left thecontext slot crashing).
nullin boththe options and context positions and asserts none throw a bare
TypeError.It also fails if a new export ships without a case, so this can't silently
come back. The suite runs from a throwaway temp directory so it never touches
the repo.
Stack
nullargumentsTest plan
init/upgrade/themesuites green (no regression from thecontext-argument change)