fix(cmd): propagate specs file write errors in test-init - #179
Conversation
runTestInitCmd discarded os.WriteFile's error, so a failed write (disk full, permission denied, target path already a directory, ...) was reported as success: "Created specs file" printed and exit 0, with nothing actually written. Left the json.MarshalIndent error un-propagated: Specs's fields are all strings/bools/*big.Int, none of which json.Marshal can fail on, so there's no reachable input that exercises that branch.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe test initialization command now propagates specs file write errors. A new internal test creates an invalid target path and checks that the command returns the expected error message. ChangesTest initialization write handling
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Approve — automated reviewThe change correctly propagates write failures from test-init and the added test covers a deterministic failure path. I did not identify any introduced correctness issues in the diff. No findings. |
Follow-up to #148 (which you closed) — recreating just the reachable half of that fix.
Background
#148 bundled two fixes: propagating
os.WriteFile's error, and propagatingjson.MarshalIndent's error (via an injectablejsonMarshalIndentvar so a test could force a failure). We determined the marshal-error path is unreachable in practice — every field inspecs_format.Specsis a string, bool, or*big.Int, none of whichencoding/json.Marshalcan fail on (no floats, no cycles, no unsupported types, and*big.Int.MarshalJSONalways succeeds) — so that half was dropped.The
os.WriteFilehalf is a real, reachable bug onmaintoday: its error is discarded (_ = os.WriteFile(...)), sotest-initprints✅ Created specs fileand exits 0 even when nothing was written (disk full, permission denied, target path already exists as a directory, etc.).Fix
Propagate
os.WriteFile's error instead of discarding it. Leftjson.MarshalIndent's error un-propagated and inline (no injection seam) — consistent with the rest of the codebase's convention of discarding errors from calls that can't realistically fail (see the_, _ = ...writes throughoutspecs_format/runner.go).Test plan
go test ./internal/cmd/...— new test creates a directory at the target.specs.jsonpath so the write deterministically fails, and asserts the error propagates with a clear message