Skip to content

Commit 23151ae

Browse files
committed
gomtree: return exit status != 0 on error
This was broken during the refactor for "gomtree validate" in commit 83c9fdb ("refactor: prefactor for adding new subcommands"), resulting in any code that relied on our exit code to silently treat all errors as non-fatal. Our tests did not catch this due to a quirky POSIX-ism with regards to "! cmd" and "set -e" which is fixed in a follow-up patch. Fixes: 83c9fdb ("refactor: prefactor for adding new subcommands") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 12e242c commit 23151ae

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

cmd/gomtree/main.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"os"
65
"strings"
76

@@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
5150
app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error {
5251
if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") {
5352
runValidate = true
54-
return nil
5553
}
5654
return err
5755
}
5856

59-
if err := app.Run(os.Args); err != nil {
60-
fmt.Println(err.Error())
61-
}
62-
63-
// So we run the command again with the validate command as the default.
64-
if runValidate {
57+
err := app.Run(os.Args)
58+
// If it failed, run the command again with the validate command as the
59+
// default if it failed.
60+
if err != nil && runValidate {
6561
app.OnUsageError = nil
6662
args := []string{os.Args[0], "validate"}
6763
args = append(args, os.Args[1:]...)
68-
if err := app.Run(args); err != nil {
69-
fmt.Println(err.Error())
70-
}
64+
err = app.Run(args)
65+
}
66+
if err != nil {
67+
logrus.Fatal(err)
7168
}
72-
7369
}

0 commit comments

Comments
 (0)