Skip to content

Conversation

@rynewang
Copy link
Contributor

@rynewang rynewang commented Jan 3, 2026

The write helper functions (write_to_end, write_tab_to_end, write_nonprint_to_end) were using .unwrap() on write operations, which would cause a panic if writing failed. This changes them to return io::Result<usize> and use ? to properly propagate errors.

The Problem

From issue #10016:

During writing, the execution result of write is captured in some places while unwrap() is directly called in others, which may trigger an abort when writing fails.

For example, in write_to_end:

// Before: panics on write error
writer.write_all(&in_buf[..p]).unwrap();

The Fix

// After: propagates error
writer.write_all(&in_buf[..p])?;

Changes

  • write_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
  • write_tab_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
  • write_nonprint_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
  • write_end: returns io::Result<usize> to propagate errors from helpers
  • Updated call site in write_lines to handle the Result with ?
  • Updated unit tests to call .unwrap() on the Result

Fixes #10016

The write helper functions (write_to_end, write_tab_to_end,
write_nonprint_to_end) were using .unwrap() on write operations,
which would cause a panic if writing failed. This changes them to
return io::Result<usize> and use ? to properly propagate errors.

Changes:
- write_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
- write_tab_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
- write_nonprint_to_end: returns io::Result<usize>, uses ? instead of .unwrap()
- write_end: returns io::Result<usize> to propagate errors from helpers
- Updated call site in write_lines to handle the Result with ?
- Updated unit tests to call .unwrap() on the Result

Fixes uutils#10016
@rynewang rynewang force-pushed the fix-cat-error-handling branch from 860ee79 to 09f9d02 Compare January 3, 2026 22:22
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 3, 2026

CodSpeed Performance Report

Merging #10038 will not alter performance

Comparing rynewang:fix-cat-error-handling (09f9d02) with main (81ee8d1)

Summary

✅ 139 untouched
⏩ 37 skipped1

Footnotes

  1. 37 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sylvestre sylvestre merged commit 8cf88cd into uutils:main Jan 4, 2026
132 of 133 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.

minor error handling issues in cat

2 participants