From 104e4d1e7a4c5e06a80bdc0b3a0392a8034c9e1f Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Fri, 17 Jan 2020 16:17:41 -0800 Subject: [PATCH] Improve error message when diff binary is not in PATH Kubernetes-commit: c1a4cd9c75b4ed476ec3ed1b27a785dd1685a6e3 --- pkg/cmd/diff/diff.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/diff/diff.go b/pkg/cmd/diff/diff.go index 8e2427d97..15179d583 100644 --- a/pkg/cmd/diff/diff.go +++ b/pkg/cmd/diff/diff.go @@ -130,7 +130,7 @@ type DiffProgram struct { genericclioptions.IOStreams } -func (d *DiffProgram) getCommand(args ...string) exec.Cmd { +func (d *DiffProgram) getCommand(args ...string) (string, exec.Cmd) { diff := "" if envDiff := os.Getenv("KUBECTL_EXTERNAL_DIFF"); envDiff != "" { diff = envDiff @@ -143,12 +143,16 @@ func (d *DiffProgram) getCommand(args ...string) exec.Cmd { cmd.SetStdout(d.Out) cmd.SetStderr(d.ErrOut) - return cmd + return diff, cmd } // Run runs the detected diff program. `from` and `to` are the directory to diff. func (d *DiffProgram) Run(from, to string) error { - return d.getCommand(from, to).Run() + diff, cmd := d.getCommand(from, to) + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to run %q: %v", diff, err) + } + return nil } // Printer is used to print an object.