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
import (
"fmt"
"os"
"strings"
@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
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") {
runValidate = true
return nil
}
return err
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err.Error())
}
// So we run the command again with the validate command as the default.
if runValidate {
err := app.Run(os.Args)
// If it failed, run the command again with the validate command as the
// default if it failed.
if err != nil && runValidate {
app.OnUsageError = nil
args := []string{os.Args[0], "validate"}
args = append(args, os.Args[1:]...)
if err := app.Run(args); err != nil {
fmt.Println(err.Error())
}
err = app.Run(args)
}
if err != nil {
logrus.Fatal(err)
}
}