ref: add better error messages

This commit is contained in:
pibragimov 2024-08-26 01:48:24 +03:00
parent 856d677ba2
commit 827dcd392a
3 changed files with 7 additions and 15 deletions

View File

@ -34,12 +34,9 @@ func main() {
} else {
util.PrintSimpleInfo()
}
if config.SystemProxy {
if err := util.SetOsProxy(uint16(config.Port)); err != nil {
logger.Fatal().Msgf("error while changing proxy settings: %s", err)
}
defer func() {
if err := util.UnsetOsProxy(); err != nil {
@ -68,9 +65,4 @@ func main() {
}()
<-done
if *config.SystemProxy {
if err := util.UnsetOsProxy(); err != nil {
log.Fatalf("error while unsetting os proxy: %v", err)
}
}
}

View File

@ -1,7 +1,6 @@
package util
import (
"errors"
"fmt"
"os/exec"
"runtime"
@ -43,14 +42,15 @@ func UnsetOsProxy() error {
}
func getDefaultNetwork() (string, error) {
network, err := exec.Command("sh", "-c", getDefaultNetworkCMD).Output()
cmd := exec.Command("sh", "-c", getDefaultNetworkCMD)
out, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("failed to get default network, stdout: %s: %w", string(network), err)
return "", fmt.Errorf("%s: %s", cmd.String(), out)
}
if len(network) == 0 {
return "", errors.New("no available networks")
if len(out) == 0 {
return "", fmt.Errorf("%s: no available networks", cmd.String())
}
return strings.TrimSpace(string(network)), nil
return strings.TrimSpace(string(out)), nil
}
func getProxyTypes() []string {