From 647dab0a6660d619824836b58d0eeb857669abcd Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Mar 2025 20:16:12 +0100 Subject: [PATCH] some cleanup --- .../bundle/exec/cmd-not-found/databricks.yml | 2 ++ .../bundle/exec/cmd-not-found/output.txt | 5 ++++ acceptance/bundle/exec/cmd-not-found/script | 1 + cmd/bundle/exec.go | 23 ++++++++++++------- 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 acceptance/bundle/exec/cmd-not-found/databricks.yml create mode 100644 acceptance/bundle/exec/cmd-not-found/output.txt create mode 100644 acceptance/bundle/exec/cmd-not-found/script diff --git a/acceptance/bundle/exec/cmd-not-found/databricks.yml b/acceptance/bundle/exec/cmd-not-found/databricks.yml new file mode 100644 index 000000000..432311dab --- /dev/null +++ b/acceptance/bundle/exec/cmd-not-found/databricks.yml @@ -0,0 +1,2 @@ +bundle: + name: foobar diff --git a/acceptance/bundle/exec/cmd-not-found/output.txt b/acceptance/bundle/exec/cmd-not-found/output.txt new file mode 100644 index 000000000..36db64667 --- /dev/null +++ b/acceptance/bundle/exec/cmd-not-found/output.txt @@ -0,0 +1,5 @@ + +>>> [CLI] bundle exec -- doesnotexist arg1 arg2 --flag1 --flag2 +Error: Running "doesnotexist arg1 arg2 --flag1 --flag2" failed: exec: "doesnotexist": executable file not found in $PATH + +Exit code: 1 diff --git a/acceptance/bundle/exec/cmd-not-found/script b/acceptance/bundle/exec/cmd-not-found/script new file mode 100644 index 000000000..4a5d442f3 --- /dev/null +++ b/acceptance/bundle/exec/cmd-not-found/script @@ -0,0 +1 @@ +trace $CLI bundle exec -- doesnotexist arg1 arg2 --flag1 --flag2 diff --git a/cmd/bundle/exec.go b/cmd/bundle/exec.go index 7dd831a20..dbd7d1156 100644 --- a/cmd/bundle/exec.go +++ b/cmd/bundle/exec.go @@ -20,6 +20,15 @@ func (e *exitCodeErr) Error() string { return fmt.Sprintf("Running %q failed with exit code: %d", strings.Join(e.args, " "), e.exitCode) } +type runErr struct { + err error + args []string +} + +func (e *runErr) Error() string { + return fmt.Sprintf("Running %q failed: %s", strings.Join(e.args, " "), e.err) +} + func newExecCommand() *cobra.Command { execCmd := &cobra.Command{ Use: "exec", @@ -84,13 +93,8 @@ Example usage: childCmd.Stdout = cmd.OutOrStdout() childCmd.Stderr = cmd.ErrOrStderr() - // Start the command - if err := childCmd.Start(); err != nil { - return fmt.Errorf("Error starting command: %s\n", err) - } - - // Wait for the command to finish. - err := childCmd.Wait() + // Run the command. + err := childCmd.Run() if exitErr, ok := err.(*exec.ExitError); ok { // We don't make the parent CLI process exit with the same exit code // as the child process because the exit codes for the CLI have not @@ -104,7 +108,10 @@ Example usage: } } if err != nil { - return fmt.Errorf("Error waiting for command: %w", err) + return &runErr{ + err: err, + args: args, + } } return nil