Skip to content

Commit

Permalink
Add more information to failed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
billy4479 committed Sep 5, 2024
1 parent 0a2865e commit cbb2a8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 1 addition & 3 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 11 additions & 15 deletions lib/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lib

import (
"errors"
"fmt"
"os"
"os/exec"
"path"
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit cbb2a8c

Please sign in to comment.