Skip to content

s2c: return failure for stdin-to-stdout stream errors - #1328

Merged
klauspost merged 2 commits into
klauspost:masterfrom
perfloop-oss:perfloop-pr-open-03vzr2234m
Nov 19, 2026
Merged

klauspost merged 2 commits into
klauspost:masterfrom
perfloop-oss:perfloop-pr-open-03vzr2234m

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

s2c - has returned success after stdin read or stdout write errors since #239: with nonempty input, s2c - < in > /dev/full exits 0 after reporting a write error. This change returns status 2 after either streaming step fails, while retaining the existing diagnostics.

(1) Save the error from closing the writer and check it alongside the read/compression error after both have been reported. The writer is still closed before exiting, so both diagnostics are reported as before.

TestStdin in s2/cmd/s2c/main_test.go runs the command in child processes. It covers failed stdin reads, failed stdout writes during compression, a write failure during close, and a successful stream that decodes to its original input. The close-only case uses empty input with padding so the failure cannot occur during reading.

The four TestStdin subtests (success, write, close, read) passed in both the default and noasm Go test builds, with no failures or skips.

This applies to stdin-to-stdout streaming only; stdin-to-file (-o) handling is unchanged.

Related work: open PR #1297 also adds s2/cmd/s2c/main_test.go and edits the same lines of s2/cmd/s2c/main.go, so the two conflict. If it lands first, this change can be rebased onto it.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

Summary by CodeRabbit

  • Bug Fixes
    • When encoding from standard input to a file, the s2c command now exits with status 2 if reading input or closing the output fails. Failures when writing to standard output continue to result in status 2.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The s2c stdin path now exits with status 2 when reading stdin or closing the S2 writer fails. A subprocess test covers successful encoding and closed stdin or stdout cases.

Changes: Stdin error handling

Layer / File(s) Summary
Stdout error handling and subprocess tests
s2/cmd/s2c/main.go, s2/cmd/s2c/main_test.go
The stdin path exits with status 2 if reading stdin or closing the writer fails. TestStdin checks successful encoding and closed-stream error cases.

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

Change: Bug fix

Possibly related PRs

  • klauspost/compress#1297: Changes the s2c output creation code and the same test file. Its changes overlap with this stdin error-handling update.

Suggested reviewers: klauspost

Merge Risk: Minimal · up to cbaf2

Piping data through s2c from stdin now exits with a failure status when reading stdin or writing stdout fails, instead of reporting success. The change is small and tested, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "s2c: return failure for stdin-to-stdout stream errors" matches the main change. The PR makes s2c - exit with status 2 when reading stdin or writing stdout fails, instead of exiting succes…
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.
Full details: Title check

Explanation

The title "s2c: return failure for stdin-to-stdout stream errors" matches the main change. The PR makes s2c - exit with status 2 when reading stdin or writing stdout fails, instead of exiting successfully after a streaming error. The raw summary lists only a one-line change from printErr to exitErr for the stdin-to-file path, and the objectives say stdin-to-file handling is unchanged. That mismatch is a separate concern from the title, which is accurate for the stdin-to-stdout behavior described in the objectives.

Finishing Touches

Simplify code

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b536d229-b9aa-402a-8a71-d6f0bc491dee
Commits

Reviewing files that changed from the base of the PR and between db0015a and cbaf290.

Files selected for processing: 2

  • s2/cmd/s2c/main.go
  • s2/cmd/s2c/main_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@klauspost

Copy link
Copy Markdown
Owner

Merged #239 - PTAL.

@klauspost

Copy link
Copy Markdown
Owner

@perfloop-agent ptal at conflicts

@klauspost

Copy link
Copy Markdown
Owner

@tsenart @perfloop Should I just wait for the "agent" to return at some point?

@tsenart

tsenart commented Nov 19, 2026

Copy link
Copy Markdown

@klauspost Sorry for the delay. We're having some hiccups. Kicking it manually.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-03vzr2234m branch from db0015a to cbaf290 Compare November 19, 2026 15:12
@perfloop-agent

Copy link
Copy Markdown
Contributor Author

Rebased onto master. #1297 rewrote the stdin block, so the fix is now one line: the stdout branch calls exitErr instead of printErr, the same as the file branch. TestStdin now expects the single joined diagnostic that master prints.

@klauspost
klauspost merged commit 401be75 into klauspost:master Nov 19, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants