From cbb2a8c1b1f1425198d60320c71e636abfa169db Mon Sep 17 00:00:00 2001 From: billy4479 Date: Thu, 5 Sep 2024 13:23:17 +0200 Subject: [PATCH] Add more information to failed commands --- lib/server.go | 4 +--- lib/utils.go | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/server.go b/lib/server.go index 31e50bb..3461b14 100644 --- a/lib/server.go +++ b/lib/server.go @@ -129,9 +129,7 @@ func (s *Server) Start(gui bool, javaProgress JavaDownloadProgress, gitProgress err := runJar(s, gui, javaProgress) if err != nil { - if err == ErrExitedAbnormally { - L.Error.Println("The server terminated with an error. Git will not update. You should first go figure out what happened to the server then git-unfuck") - } + L.Error.Println("The server terminated with an error. Git will not update. You should first go figure out what happened to the server then git-unfuck") return err } diff --git a/lib/utils.go b/lib/utils.go index 3608788..d4849f8 100644 --- a/lib/utils.go +++ b/lib/utils.go @@ -1,7 +1,7 @@ package lib import ( - "errors" + "fmt" "os" "os/exec" "path" @@ -10,10 +10,6 @@ import ( const ProgName = "server-tool" -var ( - ErrExitedAbnormally = errors.New("Aborted due to a failed command") -) - func MakeCacheDir() (err error) { if C.Application.CacheDir == "" { C.Application.CacheDir, err = os.UserCacheDir() @@ -31,18 +27,18 @@ func MakeCacheDir() (err error) { } func RunCmdPretty(workDir string, name string, args ...string) error { - { - cmdLine := name - if filepath.IsAbs(name) { - _, cmdLine = path.Split(name) - } - for _, arg := range args { - cmdLine += " " + arg - } + cmdLine := name + if filepath.IsAbs(name) { + _, cmdLine = path.Split(name) + } - L.Debug.Printf("Running \"%s\"\n", cmdLine) + for _, arg := range args { + cmdLine += " " + arg } + + L.Debug.Printf("Running \"%s\"\n", cmdLine) + cmd := exec.Command(name, args...) cmd.Stdout = L.Writer cmd.Stderr = L.Writer @@ -60,7 +56,7 @@ func RunCmdPretty(workDir string, name string, args ...string) error { } if !cmd.ProcessState.Success() { L.Warn.Printf("Command exited with code %d\n", cmd.ProcessState.ExitCode()) - return ErrExitedAbnormally + return fmt.Errorf("Command failed with code %d. The command that failed was %s", cmd.ProcessState.ExitCode(), cmdLine) } }