fix(output): propagate serialization and write failures - #232
Open
Gautam Sharma (GautamSharma99) wants to merge 1 commit into
Open
fix(output): propagate serialization and write failures#232Gautam Sharma (GautamSharma99) wants to merge 1 commit into
Gautam Sharma (GautamSharma99) wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #224.
Problem
The shared output helpers previously treated several failure modes as success:
OutputJSONprinted marshal/write errors but returned normallyOutputJSONLignored marshal, write, newline, and deferred-close errorsPrintOutputignored marshal andos.WriteFileerrors entirelyIn the JSONL path, the CLI printed
{"status":"written"}even if an earlier write or the final close failed. Commands therefore exited with status 0 after producing a missing or truncated export.Implementation
Error-returning output APIs
The following internal output functions now return
error:Errors include operation and path context while retaining the underlying error for
errors.Is/errors.As.JSON output now checks:
json.MarshalIndentJSONL output now checks:
On a write failure, the file is closed best-effort and no success status is printed. On normal completion, close is performed and checked before success is reported.
Command propagation
All command call sites now use three checked command-layer wrappers. Those wrappers feed output failures through the CLI's existing
ExitErrorfpolicy, producing an actionable stderr error and a non-zero process exit. This keeps existing command callbacks and successful output schemas unchanged while ensuring no helper error is ignored.Most command-file changes in this PR are the mechanical replacement of:
with:
The wrappers are the only command-layer callers of the error-returning output APIs.
Trace export
Trace export writes one JSONL file per trace without using the shared JSONL helper because it has per-trace extraction behavior. Its loop now:
io.ErrShortWriteThe final
countcan no longer include a trace whose file failed to finish writing.Behavior
Successful output and status payloads remain unchanged.
On failure, commands now behave like:
No
"status": "written"line is emitted for failed writes or failed closes.Tests
Added deterministic coverage for:
io.ErrShortWriteExisting success tests now assert that the output helpers return
nil.Local verification:
go test ./...go test -race ./...go vet ./...make buildgit diff --checkmake lintwas not available locally becausegolangci-lintis not installed.