Created originally in Butane by @deepak0x: coreos/butane#726
name
Bug report
about
io.ReadAll error message uses infile.Name() instead of the filename variable
title
stdin read error message uses wrong name
labels
kind/bug
warning
No response
Bug Description
In internal/main.go, when io.ReadAll fails on line 127, the error message is formatted using infile.Name():
// internal/main.go, line 127 (commit cb34e120)
fail("failed to read %s: %v\n", infile.Name(), err)
https://github.com/coreos/butane/blob/cb34e120e5267bfd5bdfa83fa8c2e44e06dedda2/internal/main.go#L127
When no --input flag is given, infile is assigned os.Stdin (line 113). os.Stdin.Name() returns "/dev/stdin" on Linux. However, the filename variable is set to "<stdin>" (line 114) for exactly this case, and updated to the real path only when --input is provided (line 122):
infile := os.Stdin
filename := "<stdin>"
if input != "" {
var err error
infile, err = os.Open(input)
if err != nil {
fail("failed to open %s: %v\n", input, err)
}
defer infile.Close()
filename = input
}
The error on line 119 and the TranslateBytes call on line 132 both use filename or input directly. Line 127 is the only site that diverges by calling infile.Name().
Current behavior
When io.ReadAll fails reading from stdin, the error reads:
failed to read /dev/stdin: <error>
Expected behavior
The error should use the same friendly identifier used everywhere else in the function:
failed to read <stdin>: <error>
Evidence
os.Stdin.Name() returns "/dev/stdin" on Linux (this is the value returned by the underlying file descriptor's name, not the user-facing label). The filename variable was explicitly initialized to "<stdin>" to present a human-readable name in messages, as is already done for the TranslateBytes report path on line 132.
Release checklist
No response
Tagging
No response
Fedora packaging
No response
GitHub release
No response
Quay release
No response
Created originally in Butane by @deepak0x: coreos/butane#726
name
Bug report
about
io.ReadAllerror message usesinfile.Name()instead of thefilenamevariabletitle
stdin read error message uses wrong name
labels
kind/bug
warning
No response
Bug Description
In
internal/main.go, whenio.ReadAllfails on line 127, the error message is formatted usinginfile.Name():https://github.com/coreos/butane/blob/cb34e120e5267bfd5bdfa83fa8c2e44e06dedda2/internal/main.go#L127
When no
--inputflag is given,infileis assignedos.Stdin(line 113).os.Stdin.Name()returns"/dev/stdin"on Linux. However, thefilenamevariable is set to"<stdin>"(line 114) for exactly this case, and updated to the real path only when--inputis provided (line 122):The error on line 119 and the
TranslateBytescall on line 132 both usefilenameorinputdirectly. Line 127 is the only site that diverges by callinginfile.Name().Current behavior
When
io.ReadAllfails reading from stdin, the error reads:Expected behavior
The error should use the same friendly identifier used everywhere else in the function:
Evidence
os.Stdin.Name()returns"/dev/stdin"on Linux (this is the value returned by the underlying file descriptor's name, not the user-facing label). Thefilenamevariable was explicitly initialized to"<stdin>"to present a human-readable name in messages, as is already done for theTranslateBytesreport path on line 132.Release checklist
No response
Tagging
No response
Fedora packaging
No response
GitHub release
No response
Quay release
No response