Skip to content

fix: send restic output to stdout - #722

Merged
creativeprojects merged 1 commit into
masterfrom
fix/dump-stdout-720
Nov 20, 2026
Merged

creativeprojects merged 1 commit into
masterfrom
fix/dump-stdout-720

Conversation

@creativeprojects

Copy link
Copy Markdown
Owner

Fixes #720

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The terminal now routes terminal-owned output to stderr without changing child-process stdout. The restic command uses a separate stdout writer that bypasses the colorable writer. Tests cover binary output and stdout-copy behaviour.

Changes

Terminal output routing

Layer / File(s) Summary
Separate terminal and command writers
main.go, term/terminal.go, term/terminal_option.go, term/terminal_test.go
The terminal has a separate writer for child-process stdout. The stderr option redirects terminal-owned output without changing that writer. Tests check binary data, ANSI sequences, and optional stdout copying.
Use the command stdout writer
wrapper.go, wrapper_test.go
The restic command now uses CommandStdout(). The dump test checks that binary output is unchanged on stdout and that stderr is empty.

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 70337

This change sends restic's output, including dump and cat data, to stdout unchanged so piping binary data works again. The change is small, localized and has tests for binary preservation and stderr routing. No blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: restic output is now sent to stdout. The raw summary shows wrapper.go now assigns restic's stdout from CommandStdout(), and the terminal adds a separate command stdou…
Description check Passed The description only reads 'Fixes #720'. It is brief and gives no implementation detail, but it links to the issue that the changeset addresses (dump and cat output routing to stdout). The check is le…
Linked Issues check Passed Issue #720 requires that restic's stdout for dump and cat reach stdout unchanged, and that resticprofile's own messages stay on stderr when --stderr is set. The reviewed head implements both:

-…
Out of Scope Changes check Passed All changed files connect to the #720 objective. The terminal changes add the separate command stdout path and the WithPrintToStderr option. wrapper.go switches restic's stdout to that path. main.go…
Full details: Title check

Explanation

The title states the main change: restic output is now sent to stdout. The raw summary shows wrapper.go now assigns restic's stdout from CommandStdout(), and the terminal adds a separate command stdout writer. This matches the linked issue #720, which asks for dump and cat output to go to stdout without binary corruption. The title is short, specific, and in the conventional commit format.

Full details: Description check

Explanation

The description only reads 'Fixes #720'. It is brief and gives no implementation detail, but it links to the issue that the changeset addresses (dump and cat output routing to stdout). The check is lenient, so it is related to the changeset and passes.

Full details: Linked Issues check

Explanation

Issue #720 requires that restic's stdout for dump and cat reach stdout unchanged, and that resticprofile's own messages stay on stderr when --stderr is set. The reviewed head implements both:

  • main.go: for flags.stderr, the terminal now uses term.WithPrintToStderr() instead of term.WithStdout(os.Stderr). Only resticprofile's own output moves to stderr.
  • wrapper.go, prepareCommand: the restic process stdout is now r.ctx.terminal.CommandStdout() instead of Stdout().
  • term/terminal.go: commandStdout is the raw t.stdout when no copy is enabled. With a copy, it is io.MultiWriter(t.stdout, colorableCopy). It does not pass through the colorable writer that strips ANSI sequences (0x1b). This addresses the byte loss described in #720.
  • term/terminal_option.go and term/terminal.go: printToStderr redirects Print*, Write and Stdout to stderr, but leaves CommandStdout unchanged.
  • Tests: TestCommandStdoutKeepsBinaryData, TestPrintToStderr, TestCommandStdoutWithCopy (term) and TestDumpBinaryOutputToStdout (wrapper) cover binary preservation and the stderr routing. I did not run them.

The suggested fix in #720 (unfiltered stdout for restic, --stderr for resticprofile messages only) is implemented. Remaining uncertainty: I did not confirm that the default t.stdout is the unwrapped os.Stdout in every code path. I read the diffs only, not the full NewTerminal defaults.

Full details: Out of Scope Changes check

Explanation

All changed files connect to the #720 objective. The terminal changes add the separate command stdout path and the WithPrintToStderr option. wrapper.go switches restic's stdout to that path. main.go swaps the stderr option. The tests cover the new behaviour. The CommandStdout method and WithPrintToStderr option are new public API, but they are required by the fix and do not add unrelated behaviour.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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: 0e77a95e-4666-49b5-8b4a-78681545ce84
Commits

Reviewing files that changed from the base of the PR and between daeff82 and 7033754.

Files selected for processing: 6

  • main.go
  • term/terminal.go
  • term/terminal_option.go
  • term/terminal_test.go
  • wrapper.go
  • wrapper_test.go

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

@creativeprojects creativeprojects added the bug Something isn't working label Nov 19, 2026
@creativeprojects creativeprojects added this to the v0.35.0 milestone Nov 19, 2026
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (daeff82) to head (7033754).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #722      +/-   ##
==========================================
+ Coverage   85.42%   85.48%   +0.06%     
==========================================
  Files         161      161              
  Lines       10399    10407       +8     
==========================================
+ Hits         8883     8896      +13     
+ Misses       1516     1511       -5     
Flag Coverage Δ
unittests 83.41% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@creativeprojects
creativeprojects merged commit 2259f67 into master Nov 20, 2026
18 checks passed
@creativeprojects
creativeprojects deleted the fix/dump-stdout-720 branch November 20, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.34.0: dump and cat write restic's output to stderr, and binary data loses bytes

1 participant