Skip to content
This repository was archived by the owner on Aug 25, 2026. It is now read-only.

main: use friendly filename in stdin read error - #728

Closed
deepak0x wants to merge 1 commit into
coreos:mainfrom
deepak0x:fix/726-stdin-read-error-name
Closed

main: use friendly filename in stdin read error#728
deepak0x wants to merge 1 commit into
coreos:mainfrom
deepak0x:fix/726-stdin-read-error-name

Conversation

@deepak0x

@deepak0x deepak0x commented Aug 2, 2026

Copy link
Copy Markdown

Summary

In internal/main.go, the io.ReadAll failure path formatted its error with infile.Name(), which returns /dev/stdin on Linux instead of the friendly <stdin> label used everywhere else in the function (and in the TranslateBytes report path).

Changes

Extracted the input-reading logic into a readInput(input string) ([]byte, string, error) helper. It returns the friendly filename (<stdin> when reading from stdin, the real path when --input/a positional file is given) so the read error message and the translation report stay consistent.

internal/main.go line 127 (now in readInput):

fail("failed to read %s: %v\n", filename, err)

filename is now <stdin> for the stdin case instead of /dev/stdin.

Verification

Added internal/main_test.go covering readInput:

  • reading from stdin yields content and the <stdin> filename
  • reading a real file yields content and the real path as filename
  • a missing file returns an error with the requested path as filename

./test passes (gofmt, go vet, full test suite, doc validation).

Before: failed to read /dev/stdin: <error>
After: failed to read <stdin>: <error>

Fixes: #726

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of input from standard input and specified files.
    • Added clearer error handling for missing or unreadable files.
  • Tests

    • Added coverage for standard input, file input, missing files, returned filenames, and failed reads.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e836934d-1fe5-463b-948c-07a59053cd60

📥 Commits

Reviewing files that changed from the base of the PR and between bc8ce88 and 02b0e94.

📒 Files selected for processing (2)
  • internal/main.go
  • internal/main_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/main.go

📝 Walkthrough

Walkthrough

The change adds readInput to handle stdin and file input. main uses the helper for reading and error reporting. Tests cover stdin input, file input, missing files, returned filenames, and cleanup.

Changes

Input reading

Layer / File(s) Summary
Read input helper and tests
internal/main.go, internal/main_test.go
readInput reads stdin or a specified file and returns input data, the effective filename, and errors. Tests cover stdin, file input, missing files, and resource cleanup.
Main input integration
internal/main.go
main uses readInput and reports read failures with the helper’s returned filename.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: using a friendly filename for stdin read errors.
Linked Issues check ✅ Passed The PR uses for stdin read errors and preserves explicit file paths, satisfying issue #726.
Out of Scope Changes check ✅ Passed The helper extraction and focused tests support the filename fix without introducing unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/main_test.go`:
- Around line 23-88: The readInput tests should be consolidated into a
table-driven TestReadInput with subtests covering stdin, file input, missing
files, and an empty-stdin edge case. Reuse the existing setup and assertions for
each case, preserving expected data, filename, and error behavior while keeping
the tests in internal/main_test.go.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d23ec70-8fd8-4776-82c3-1751726923de

📥 Commits

Reviewing files that changed from the base of the PR and between cb34e12 and bc8ce88.

📒 Files selected for processing (2)
  • internal/main.go
  • internal/main_test.go

Comment thread internal/main_test.go Outdated
The io.ReadAll failure message used infile.Name(), which returns
/dev/stdin on Linux instead of the user-facing <stdin> label already
used everywhere else in main(). Extract the input reading into
readInput so the friendly filename (<stdin> for stdin, the real path
otherwise) is used consistently in both the read error and the
translation report.

Fixes: coreos#726
Signed-off-by: Deepak Bhagat <deepak988088@gmail.com>
@deepak0x
deepak0x force-pushed the fix/726-stdin-read-error-name branch from bc8ce88 to 02b0e94 Compare August 2, 2026 11:44
@deepak0x

Copy link
Copy Markdown
Author

Closing in favor of coreos/ignition#2293. Butane is merging into Ignition (see coreos/ignition#2281), so the fix for the stdin read error now lives there. ignition#2293 ports this exact change, including the readInput helper and the main_test.go table tests, so this Butane PR is no longer needed.

@deepak0x deepak0x closed this Aug 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: stdin read error message uses wrong name

1 participant