From 7b09ac0cda1ba1ceef989d467634b97b7e08b676 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sun, 8 Sep 2024 21:30:18 +0200 Subject: [PATCH] basic proxy error handling; exit on read proxy error --- proxy/debug.go | 8 +++++++- proxy/set.go | 9 ++++++--- proxy/unset.go | 9 ++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/proxy/debug.go b/proxy/debug.go index bba1499..5d2cbb8 100644 --- a/proxy/debug.go +++ b/proxy/debug.go @@ -2,6 +2,7 @@ package proxy import ( "fmt" + "log" "strings" "github.com/Baipyrus/ProxySwitcher/util" @@ -20,7 +21,12 @@ func mapCmdsToStr(commands []*util.Command) string { } func Debug() { - proxy, _ := ReadSystemProxy() + proxy, err := ReadSystemProxy() + + if err != nil { + log.Fatal(err) + } + fmt.Println("\nSystem Proxy:") fmt.Printf("Enabled: %t\n", proxy.Enabled) fmt.Printf("Server: %s\n\n", proxy.Server) diff --git a/proxy/set.go b/proxy/set.go index 00c0b7f..6892490 100644 --- a/proxy/set.go +++ b/proxy/set.go @@ -1,16 +1,19 @@ package proxy import ( + "log" + "github.com/Baipyrus/ProxySwitcher/util" ) func Set() { stdin, closeFunc, _ := util.ReadyCmd() - proxy, _ := ReadSystemProxy() // Set system proxy, if not already - if !proxy.Enabled { - SetSystemProxy(true) + proxy, err := ReadSystemProxy() + + if err != nil { + log.Fatal(err) } configs, _ := util.ReadConfigs() diff --git a/proxy/unset.go b/proxy/unset.go index f4eade3..b9964d4 100644 --- a/proxy/unset.go +++ b/proxy/unset.go @@ -1,6 +1,8 @@ package proxy import ( + "log" + "github.com/Baipyrus/ProxySwitcher/util" ) @@ -8,7 +10,12 @@ func Unset() { stdin, closeFunc, _ := util.ReadyCmd() // Unset system proxy, if not already - proxy, _ := ReadSystemProxy() + proxy, err := ReadSystemProxy() + + if err != nil { + log.Fatal(err) + } + if proxy.Enabled { SetSystemProxy(false) }