Skip to content

Commit

Permalink
Add help message when diff fails (#1466)
Browse files Browse the repository at this point in the history
* Add help message when diff fails
  • Loading branch information
runewake2 committed Feb 18, 2021
1 parent ca4befc commit 39c45a0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/util/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ const (
targetRemotePackageSource string = "target"
)

const (
exitCodeDiffWarning string = "\nThe selected diff tool (%s) exited with an " +
"error. It may not support the chosen diff type (%s). To use a different " +
"diff tool please provide the tool using the --diff-tool flag. \n\nFor " +
"more information about using kpt's diff command please see the commands " +
"--help.\n"
)

// String implements Stringer.
func (dt DiffType) String() string {
return string(dt)
Expand Down Expand Up @@ -279,11 +287,15 @@ func (d *defaultPkgDiffer) Diff(pkgs ...string) error {
}
err := cmd.Run()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok &&
exitErr.ExitCode() == 1 {
exitErr, ok := err.(*exec.ExitError)
if ok && exitErr.ExitCode() == 1 {
// diff tool will exit with return code 1 if there are differences
// between two dirs. This suppresses those errors.
err = nil
} else if ok {
// An error occurred but was not one of the excluded ones
// Attempt to display help information to assist with resolving
fmt.Printf(exitCodeDiffWarning, d.DiffTool, d.DiffType)
}
}
return err
Expand Down

0 comments on commit 39c45a0

Please sign in to comment.