Skip to content

Commit

Permalink
Improve error messages when Java commands fail (#1464)
Browse files Browse the repository at this point in the history
When we fail to execute a Java command, we currently duplicate the
command name (e.g. `mvn`), which makes it harder to understand what has
gone wrong. This commit cleans this up, additionally quoting the command
we attempted to run so that it's easier to parse in the event it
contains spaces.
  • Loading branch information
lunaris authored Nov 18, 2024
1 parent 2a665a8 commit 1663ca5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/cmd/pulumi-language-java/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

// Like `cmd.Run()` but issues friendlier errors.
func runCommand(cmd *exec.Cmd) error {
name := cmd.Path
commandStr := strings.Join(cmd.Args, " ")
if err := cmd.Run(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
Expand All @@ -20,16 +19,16 @@ func runCommand(cmd *exec.Cmd) error {
// So, the error message should look as nice as possible.
if status, stok := exiterr.Sys().(syscall.WaitStatus); stok {
code := status.ExitStatus()
return fmt.Errorf("'%v %v' exited with non-zero exit code: %d", name, commandStr, code)
return fmt.Errorf("'%v' exited with non-zero exit code: %d", commandStr, code)
}
return fmt.Errorf("'%v %v' exited unexpectedly: %w", name, commandStr, exiterr)
return fmt.Errorf("'%v' exited unexpectedly: %w", commandStr, exiterr)
}

// Otherwise, we didn't even get to run the program.
// This ought to never happen unless there's a bug or
// system condition that prevented us from running the
// language exec. Issue a scarier error.
return fmt.Errorf("Problem executing '%v %v': %w", name, commandStr, err)
return fmt.Errorf("Problem executing '%v': %w", commandStr, err)
}
return nil
}

0 comments on commit 1663ca5

Please sign in to comment.