Skip to content

Commit

Permalink
fix: convert exitErr to commandError if runCommand fails
Browse files Browse the repository at this point in the history
exitError must not exit the runCommand helper, only commandError
safety check when casting in segment_language
  • Loading branch information
lnu authored and JanDeDobbeleer committed Jan 15, 2021
1 parent f8b28f0 commit 31c77af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/environment.go
Expand Up @@ -170,7 +170,12 @@ func (env *environment) runCommand(command string, args ...string) (string, erro
}
out, err := exec.Command(command, args...).Output()
if err != nil {
return "", err
if exitErr, ok := err.(*exec.ExitError); ok {
return "", &commandError{
err: exitErr.Error(),
exitCode: exitErr.ExitCode(),
}
}
}
return strings.TrimSpace(string(out)), nil
}
Expand Down
5 changes: 3 additions & 2 deletions src/segment_language.go
Expand Up @@ -77,9 +77,10 @@ func (l *language) getVersion() bool {
l.exitCode = 0
l.version = values["version"]
} else {
errors.As(err, &exerr)
l.exitCode = exerr.exitCode
l.version = ""
if errors.As(err, &exerr) {
l.exitCode = exerr.exitCode
}
}
return true
}
Expand Down

0 comments on commit 31c77af

Please sign in to comment.