Skip to content

Commit 0a622e3

Browse files
committed
dump descriptive source info on error instead of the source data
Signed-off-by: Jordan Keister <[email protected]>
1 parent f45718e commit 0a622e3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cmd/opm/alpha/veneer/semver.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func newSemverCmd() *cobra.Command {
2727
// When no arguments or "-" is passed to the command,
2828
// assume input is coming from stdin
2929
// Otherwise open the file passed to the command
30-
data, err := openFileOrReadStdin(cmd, args)
30+
data, source, err := openFileOrReadStdin(cmd, args)
3131
if err != nil {
3232
return err
3333
}
@@ -64,7 +64,7 @@ func newSemverCmd() *cobra.Command {
6464
}
6565
out, err := veneer.Render(cmd.Context())
6666
if err != nil {
67-
log.Fatalf("semver %q: %v", data, err)
67+
log.Fatalf("semver %q: %v", source, err)
6868
}
6969

7070
if out != nil {
@@ -81,9 +81,17 @@ func newSemverCmd() *cobra.Command {
8181
return cmd
8282
}
8383

84-
func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, error) {
84+
func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, string, error) {
85+
var err error = nil
86+
var source string = ""
87+
var reader io.Reader
88+
8589
if len(args) == 0 || args[0] == "-" {
86-
return cmd.InOrStdin(), nil
90+
reader = cmd.InOrStdin()
91+
source = "stdin"
92+
} else {
93+
reader, err = os.Open(args[0])
94+
source = "args[0]"
8795
}
88-
return os.Open(args[0])
96+
return reader, source, err
8997
}

0 commit comments

Comments
 (0)