Skip to content

fix(cmd): propagate specs file write errors in test-init - #179

Open
ascandone wants to merge 1 commit into
mainfrom
fix/test-init-propagate-write-error
Open

fix(cmd): propagate specs file write errors in test-init#179
ascandone wants to merge 1 commit into
mainfrom
fix/test-init-propagate-write-error

Conversation

@ascandone

Copy link
Copy Markdown
Contributor

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 propagating json.MarshalIndent's error (via an injectable jsonMarshalIndent var so a test could force a failure). We determined the marshal-error path is unreachable in practice — every field in specs_format.Specs is a string, bool, or *big.Int, none of which encoding/json.Marshal can fail on (no floats, no cycles, no unsupported types, and *big.Int.MarshalJSON always succeeds) — so that half was dropped.

The os.WriteFile half is a real, reachable bug on main today: its error is discarded (_ = os.WriteFile(...)), so test-init prints ✅ Created specs file and 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. Left json.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 throughout specs_format/runner.go).

Test plan

  • go test ./internal/cmd/... — new test creates a directory at the target .specs.json path so the write deterministically fails, and asserts the error propagates with a clear message

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.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 615e6fcc-4964-4db0-8d3b-3ad6b1e3dfa3

📥 Commits

Reviewing files that changed from the base of the PR and between 93f89d1 and b432efe.

📒 Files selected for processing (2)
  • internal/cmd/test_init.go
  • internal/cmd/test_init_internal_test.go

Walkthrough

The 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.

Changes

Test initialization write handling

Layer / File(s) Summary
Write error handling and regression test
internal/cmd/test_init.go, internal/cmd/test_init_internal_test.go
runTestInitCmd now returns a formatted error when os.WriteFile fails. The test verifies this behavior by using a directory at the specs file path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit found a silent write,
And made its error known.
A test blocked the target path,
Then checked the message shown.
“Good hops!” the rabbit said.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: propagating specs file write errors in test-init.
Description check ✅ Passed The description directly explains the write-error fix, its rationale, and the test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-init-propagate-write-error

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NumaryBot

Copy link
Copy Markdown
Contributor

✅ Approve — automated review

The 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.

@ascandone
ascandone requested a review from Azorlogh August 4, 2026 13:43
@ascandone
ascandone enabled auto-merge (squash) August 5, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants