Repository navigation
fix(cli): a failed write reports ERR_WRITE_FAILED, not a raw Node errno - #6621
Conversation
template into an unwritable directory returned {"error": "EACCES: permission
denied, open '/abs/host/path/readonly/x.tsx'", "code": "ERR_UNKNOWN"}, and
swizzle returned the mkdir equivalent. ERR_WRITE_FAILED is already in the frozen
registry for exactly this, and every other Astryx message names its target
relative to the project. Nothing is partially written, so only the code and the
message were wrong.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression15 of 420 shot(s) changed. A change here is a question, not a failure: check whether the after is the
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Thanks — the core fix is right: a refused write now reports ERR_WRITE_FAILED with the target named relative to the project, instead of a raw Node errno as ERR_UNKNOWN with an absolute host path. The regression test covers both commands plus the unchanged happy path, and the docs and changeset line up.
One change is requested before approval. When swizzle fails part-way through copying, files it already wrote stay on disk, but the new message always ends "Nothing was written." — which also contradicts the registry's own description of this code ("and was rolled back"). Someone told nothing was written will retry without --overwrite and immediately hit the overwrite refusal, with a partial component left behind. Please make that one report truthful (name the partial state, or roll back like the theme writers do) and adjust the matching sentence in the helper comment and changeset. The mkdir failures and the single-file template case are fine as written.
Everything else looks good to merge once that wording is fixed.
[Automated review]
Review fix. ERR_WRITE_FAILED means the write failed and was rolled back, but a swizzle that failed on a later file left the earlier ones on disk while the message said nothing was written. It now deletes the files it created and puts back the bytes of any it replaced before reporting, and writeFailed names any file an undo could not restore instead of claiming nothing was written. New test: with the last file read-only, an --overwrite swizzle restores the first file, removes the new ones, and reports 'Nothing was written.'; it fails without the undo.
There was a problem hiding this comment.
Thanks — the rollback added in this revision fixes the part-way swizzle case from the last review: the new test passes (4/4 locally), replaced files are restored, and created files are removed before the error is reported.
One related case still needs a fix before approval. The rollback snapshots each existing destination with fs.readFileSync(dest) before the try that guards the write. If that destination cannot be read back — an unreadable file (mode 000) or a directory with a copied file's name — the snapshot read itself throws, so the raw errno escapes as ERR_UNKNOWN (with the absolute host path in the unreadable case) and files copied earlier in the run stay overwritten instead of being restored. Please capture the snapshot inside the protected block so any throw there first undoes the entries already written and then reports ERR_WRITE_FAILED, and add a regression case for an unreadable or directory destination.
Everything else looks good to merge once that is fixed.
[Automated review]
Review fix. The rollback read each existing destination before the guarded write, so a destination that cannot be read back (no permission, or a directory with a copied file's name) threw a raw errno as ERR_UNKNOWN and left the earlier files overwritten. The snapshot read now sits inside the guarded block: a throw there undoes the entries already written and reports ERR_WRITE_FAILED. New test: a directory where the last file goes; it fails with ERR_UNKNOWN when the snapshot is outside the guard.
There was a problem hiding this comment.
Thanks — this revision closes the last case from the previous review. The rollback snapshot read is now inside the guarded block, so a destination that cannot be read back (an unreadable file, or a directory with a copied file's name) undoes the files already copied and reports ERR_WRITE_FAILED with a project-relative path, instead of escaping as ERR_UNKNOWN.
I re-verified at this revision: the write-failure suite passes 5/5 (including the new directory-destination case), an added check with a mode-000 destination file also reports ERR_WRITE_FAILED and restores the earlier file, and the adjacent envelope/exit-code/error-code suites pass. The core fix — refused writes reporting the existing ERR_WRITE_FAILED code without leaking an absolute host path, with part-way swizzle copies rolled back — looks good to merge.
[Automated review]
Mechanical refresh. #6621 (merged as 31feb21) moved template copy's source read before the write and wrapped the mkdir and write in ERR_WRITE_FAILED; this PR changed that read to replaceDemoMedia(). The resolution keeps both: the replaceDemoMedia() read before the guarded mkdir+write. #6618 (merged as 6e56409) changed the generated README tables, so they are regenerated.
User impact
A write the filesystem refuses comes back as a raw Node errno error with the
wrong error code and an absolute host path in the message:
swizzle --output <unwritable>returned themkdirequivalent. A consumerbranching on
code— which is the field the contract says to branch on — seesERR_UNKNOWNand cannot tell a permissions problem from a bug in the CLI. Andthe absolute path lands wherever the envelope lands: a CI log, an agent
transcript, a pasted bug report.
Problem and solution fit
Why does it happen? Nothing wraps the
fscall, so Node's error reaches theenvelope untranslated and picks up the default
ERR_UNKNOWN.Why does that harm the task? "Unknown" tells the user to report a bug when the
answer is
chmod. Retry logic and agents branch on the code and get nothinguseful.
Why does that matter?
ERR_WRITE_FAILEDis already in the frozen registry forexactly this case and already used by
integration add. Two write leaves weresimply missing from it.
Expected behavior and authority
ERR_WRITE_FAILEDfromfoundation/response/error-codes.mjs, already the codeapi/integration/add-contribution.mjsthrows for a failed write. Messages nametheir target relative to the project (
copy.mjsalready does this forERR_FILE_EXISTS:
`Refusing to overwrite existing file ${rel}`).Smallest restoration
Nothing is partially written in either case, so only the code and the message
were wrong. One shared
writeFailed(target, cwd, cause)inapi/error.mjsbuilds the error; the two write leaves wrap their
fscalls with it.api/template/copy/copy.mjs— the source is now read before themkdir, soa failure below cannot leave a created directory behind.
api/swizzle/copy/copy.mjs— themkdirand the per-file write.The errno is kept (
EACCESis the part that tells you what to fix); the path isthe project-relative one.
ERR_WRITE_FAILEDis added to both FunctionDocs'throws.Evidence
Reproduction before the change:
Result after the change:
Representative unchanged path:
template ai-chat src/page.tsxinto a writabledirectory still returns
template.copyand exit 0 with the file on disk;ERR_FILE_EXISTS, ERR_PATH_TRAVERSAL and the rest are untouched.
Regression test or other mutation-sensitive proof:
clients/cli/commands/write-failure.test.mjs, 3 tests. Verified in bothdirections — with
api/error.mjsand the two copy leaves reverted tomainandonly the test applied, 2 fail (
expected 'ERR_UNKNOWN' to be 'ERR_WRITE_FAILED'); with the fix all 3 pass. The tests also assert theabsolute temp-dir path does not appear in the message, and that nothing was
created. They skip under uid 0, where
chmod 500would not make the directoryunwritable and the assertion would be false rather than failing honestly.
Full
packages/clinode suite green, pluscheck:repo,eslint,readme:checkand the CLI typechecks in an unbuilt tree.Scope
No response field changes.
ERR_WRITE_FAILEDis an existing registry entry, nowreachable from two more places and documented in both FunctionDocs.
Review fix (head b16941f, on main 505e3d8)
The review found that a
swizzlefailing part-way left the files it had already copied on disk, while the message said "Nothing was written." That also contradicts the registry's meaning for this code ("failed (and was rolled back)"). A swizzle that fails on a later file now undoes the copy before reporting: it deletes the files it created and puts back the bytes of any it replaced.writeFailedtakes the files an undo could not restore and names them, instead of claiming nothing was written. The helper's comment and the changeset now say this.New test in
write-failure.test.mjs: the first output file exists, the middle ones do not, and the last one is read-only. An--overwriteswizzle then fails on the last file, puts the first file back, removes the new ones, and reports "Nothing was written." With the undo removed, the test fails (expected '// Copyright…' to be 'before first\n').Evidence on that tree: the full CLI node suite (350 files, 5,555 tests),
check:cli-structure,check:changesets,readme:check,typecheck:json-api,typecheck:authoring,cli-api-types-verify, eslint, and prettier all pass.Review fix 2 (head 7d04911, on main 5bb03cf)
The review found one more case. The rollback snapshot read each existing destination before the guarded write. A destination that cannot be read back (no permission, or a directory with a copied file's name) threw a raw errno as
ERR_UNKNOWN, with the absolute path in the unreadable case, and left the earlier files overwritten. The snapshot read now sits inside the guarded block. A throw there undoes the entries already written and reportsERR_WRITE_FAILED. The destination that failed is not in the undo list, because nothing was written to it.New test: a directory sits where the last file goes. The
--overwriteswizzle reportsERR_WRITE_FAILEDnaming that file, puts the first file back, removes the new ones, and leaves the directory. With the snapshot back outside the guard, it fails (expected 'ERR_UNKNOWN' to be 'ERR_WRITE_FAILED').Evidence: on main 9143f03 plus this fix, the full CLI node suite (354 files, 5,576 tests),
check:cli-structure,check:changesets,readme:check, both typechecks,cli-api-types-verify, eslint and prettier pass. The pushed head also merges main 5bb03cf (#6615), and the fix commit is byte-identical to the tested fix.