1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-09-13 22:03:19 +00:00

gomtree: return exit status != 0 on error

This was broken during the refactor for "gomtree validate" in commit
83c9fdb78b ("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: 83c9fdb78b ("refactor: prefactor for adding new subcommands")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2025-09-08 21:52:22 +10:00
parent 12e242c268
commit 23151ae80f
No known key found for this signature in database
GPG key ID: 2897FAD2B7E9446F

View file

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"os" "os"
"strings" "strings"
@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error { app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error {
if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") { if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") {
runValidate = true runValidate = true
return nil
} }
return err return err
} }
if err := app.Run(os.Args); err != nil { err := app.Run(os.Args)
fmt.Println(err.Error()) // If it failed, run the command again with the validate command as the
} // default if it failed.
if err != nil && runValidate {
// So we run the command again with the validate command as the default.
if runValidate {
app.OnUsageError = nil app.OnUsageError = nil
args := []string{os.Args[0], "validate"} args := []string{os.Args[0], "validate"}
args = append(args, os.Args[1:]...) args = append(args, os.Args[1:]...)
if err := app.Run(args); err != nil { err = app.Run(args)
fmt.Println(err.Error()) }
if err != nil {
logrus.Fatal(err)
} }
} }
}