Skip to content

OCPBUGS-1004: dump descriptive source info on error instead of the source data (#1021) #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions staging/operator-registry/cmd/opm/alpha/veneer/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newSemverCmd() *cobra.Command {
// When no arguments or "-" is passed to the command,
// assume input is coming from stdin
// Otherwise open the file passed to the command
data, err := openFileOrReadStdin(cmd, args)
data, source, err := openFileOrReadStdin(cmd, args)
if err != nil {
return err
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func newSemverCmd() *cobra.Command {
}
out, err := veneer.Render(cmd.Context())
if err != nil {
log.Fatalf("semver %q: %v", data, err)
log.Fatalf("semver %q: %v", source, err)
}

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

func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, error) {
func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, string, error) {
var err error = nil
var source string = ""
var reader io.Reader

if len(args) == 0 || args[0] == "-" {
return cmd.InOrStdin(), nil
reader = cmd.InOrStdin()
source = "stdin"
} else {
reader, err = os.Open(args[0])
source = args[0]
}
return os.Open(args[0])
return reader, source, err
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.