Skip to content

Fix panic when printing the help, version, or specification output fails - #174

Merged
ia0 merged 3 commits into
ia0:mainfrom
17krishna8:fix-print-panic
Oct 7, 2026
Merged

ia0 merged 3 commits into
ia0:mainfrom
17krishna8:fix-print-panic

Conversation

@17krishna8

Copy link
Copy Markdown
Contributor

The help, version, and specification outputs are printed with print!/println!, which panic when the write fails (for example with a broken pipe or a full disk) instead of returning a write error like the encode and decode modes do:

$ data-encoding --mode=specification --base=64 | head -0
thread 'main' panicked at library/std/src/io/stdio.rs:1168:9:
failed printing to stdout: Broken pipe (os error 32)

$ data-encoding --version > /dev/full
thread 'main' panicked at library/std/src/io/stdio.rs:1168:9:
failed printing to stdout: No space left on device (os error 28)

$ data-encoding --help > /dev/full
thread 'main' panicked at library/std/src/io/stdio.rs:1168:9:
failed printing to stdout: No space left on device (os error 28)

This replaces those macros with write!/writeln! on std::io::stdout() so that write errors are reported like the other modes:

$ data-encoding --mode=specification --base=64 | head -0
data-encoding: Write error: Broken pipe (os error 32)

$ data-encoding --version > /dev/full
data-encoding: Write error: No space left on device (os error 28)

Since all three outputs end with a newline, the line-buffered stdout flushes before wrapped_main returns, so no flush error is dropped. Follows the pattern of #172.

@ia0
ia0 force-pushed the fix-print-panic branch from 536c79a to 1786f29 Compare October 7, 2026 08:35

@ia0 ia0 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've also made sure there's no silent errors when flushing.

@ia0
ia0 merged commit c0ffda7 into ia0:main Oct 7, 2026
2 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.

2 participants