fix: showing the entire error message when a command fails

This commit is contained in:
Simone Margaritelli 2021-05-14 15:26:50 +02:00
commit dfe64ee4db
2 changed files with 7 additions and 4 deletions

View file

@ -41,7 +41,7 @@ func Exec(executable string, args []string) (string, error) {
raw, err := exec.Command(path, args...).CombinedOutput()
if err != nil {
return "", err
return str.Trim(string(raw)), err
} else {
return str.Trim(string(raw)), nil
}

View file

@ -279,7 +279,11 @@ func SetWiFiRegion(region string) error {
func ActivateInterface(name string) error {
if out, err := core.Exec("ifconfig", []string{name, "up"}); err != nil {
return err
if out != "" {
return fmt.Errorf("%v: %s", err, out)
} else {
return err
}
} else if out != "" {
return fmt.Errorf("unexpected output while activating interface %s: %s", name, out)
}
@ -289,8 +293,7 @@ func ActivateInterface(name string) error {
func SetInterfaceTxPower(name string, txpower int) error {
if core.HasBinary("iw") {
Debug("SetInterfaceTxPower(%s, %d) iw based", name, txpower)
if _, err := core.Exec("iw", []string{"dev", name, "set", "txpower", "fixed", fmt.Sprintf("%d",
txpower)}); err != nil {
if _, err := core.Exec("iw", []string{"dev", name, "set", "txpower", "fixed", fmt.Sprintf("%d", txpower)}); err != nil {
return err
}
} else if core.HasBinary("iwconfig") {