mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
ref: add better error messages
This commit is contained in:
parent
856d677ba2
commit
827dcd392a
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
util/os.go
12
util/os.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user