diff --git a/cloudflare/util/util.go b/cloudflare/util/util.go index a7364b1..af89373 100644 --- a/cloudflare/util/util.go +++ b/cloudflare/util/util.go @@ -1,7 +1,7 @@ package util import ( - "errors" + "github.com/pkg/errors" "time" "wgcf/cloudflare/structs/resp" ) diff --git a/cloudflare/util/web.go b/cloudflare/util/web.go index 3a2022b..fc40d8f 100644 --- a/cloudflare/util/web.go +++ b/cloudflare/util/web.go @@ -2,8 +2,8 @@ package util import ( "encoding/json" - "errors" "fmt" + "github.com/pkg/errors" "io" "io/ioutil" "net/http" diff --git a/cmd/generate/generate.go b/cmd/generate/generate.go index 80d20ec..776c180 100644 --- a/cmd/generate/generate.go +++ b/cmd/generate/generate.go @@ -1,13 +1,14 @@ package generate import ( - "errors" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" "log" "wgcf/cloudflare/api" . "wgcf/cmd/util" "wgcf/config" + "wgcf/util" "wgcf/wireguard" ) @@ -21,7 +22,7 @@ var Cmd = &cobra.Command{ Will change various account settings to ensure WireGuard connection will succeed.`), Run: func(cmd *cobra.Command, args []string) { if err := generateProfile(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/register/register.go b/cmd/register/register.go index 4af7bd9..e757a4c 100644 --- a/cmd/register/register.go +++ b/cmd/register/register.go @@ -1,9 +1,9 @@ package register import ( - "errors" "fmt" "github.com/manifoldco/promptui" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" "log" @@ -11,6 +11,7 @@ import ( "wgcf/cloudflare/url" . "wgcf/cmd/util" "wgcf/config" + "wgcf/util" "wgcf/wireguard" ) @@ -27,7 +28,7 @@ var Cmd = &cobra.Command{ Will change various account settings to ensure WireGuard connection will succeed.`), Run: func(cmd *cobra.Command, args []string) { if err := registerAccount(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/root.go b/cmd/root.go index b2e3bfa..97910f5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,8 +9,9 @@ import ( "wgcf/cmd/status" "wgcf/cmd/trace" "wgcf/cmd/update" - "wgcf/cmd/util" + . "wgcf/cmd/util" "wgcf/config" + "wgcf/util" ) var cfgFile string @@ -18,13 +19,13 @@ var cfgFile string var RootCmd = &cobra.Command{ Use: "wgcf", Short: "WireGuard Cloudflare Warp utility", - Long: util.FormatMessage("", ` + Long: FormatMessage("", ` wgcf is a utility for Cloudflare Warp that allows you to create and manage accounts, assign license keys, and generate WireGuard profiles. Made by Victor (@ViRb3). Project website: https://github.com/ViRb3/wgcf`), Run: func(cmd *cobra.Command, args []string) { if err := cmd.Help(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/status/status.go b/cmd/status/status.go index e8175e8..033eead 100644 --- a/cmd/status/status.go +++ b/cmd/status/status.go @@ -1,11 +1,12 @@ package status import ( - "errors" + "github.com/pkg/errors" "github.com/spf13/cobra" "log" "wgcf/cloudflare/api" . "wgcf/cmd/util" + "wgcf/util" ) var shortMsg = "Prints the status of the current Cloudflare Warp device" @@ -16,7 +17,7 @@ var Cmd = &cobra.Command{ Long: FormatMessage(shortMsg, ""), Run: func(cmd *cobra.Command, args []string) { if err := status(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/trace/trace.go b/cmd/trace/trace.go index 9aada3a..78c35ad 100644 --- a/cmd/trace/trace.go +++ b/cmd/trace/trace.go @@ -8,6 +8,7 @@ import ( "net/http" "strings" . "wgcf/cmd/util" + "wgcf/util" ) var shortMsg = "Prints trace information about the current internet connection" @@ -19,7 +20,7 @@ var Cmd = &cobra.Command{ Useful for verifying if Warp and Warp+ are working.`), Run: func(cmd *cobra.Command, args []string) { if err := trace(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/update/update.go b/cmd/update/update.go index 81216c9..8e02b94 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -1,7 +1,7 @@ package update import ( - "errors" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" "log" @@ -9,6 +9,7 @@ import ( "wgcf/cloudflare/structs/resp" . "wgcf/cmd/util" "wgcf/config" + "wgcf/util" ) var deviceName string @@ -24,7 +25,7 @@ Please note that there is a maximum limit of 5 active devices linked to the same Will change various account settings to ensure WireGuard connection will succeed.`), Run: func(cmd *cobra.Command, args []string) { if err := updateAccount(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } }, } diff --git a/cmd/util/util.go b/cmd/util/util.go index 0e22572..23d674f 100644 --- a/cmd/util/util.go +++ b/cmd/util/util.go @@ -1,7 +1,7 @@ package util import ( - "errors" + "github.com/pkg/errors" "github.com/spf13/viper" "log" "strings" diff --git a/go.mod b/go.mod index d7cdbf6..d2563e8 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.13 require ( github.com/manifoldco/promptui v0.7.0 github.com/pelletier/go-toml v1.7.0 // indirect + github.com/pkg/errors v0.8.0 github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.6.3 golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 diff --git a/go.sum b/go.sum index cdb5959..21fb01a 100644 --- a/go.sum +++ b/go.sum @@ -94,6 +94,7 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/main.go b/main.go index 9eab999..5a02924 100644 --- a/main.go +++ b/main.go @@ -3,10 +3,11 @@ package main import ( "log" "wgcf/cmd" + "wgcf/util" ) func main() { if err := cmd.Execute(); err != nil { - log.Fatal(err) + log.Fatal(util.GetErrorMessage(err)) } } diff --git a/util/url.go b/util/url.go index b74bc04..bf3eac1 100644 --- a/util/url.go +++ b/util/url.go @@ -1,6 +1,7 @@ package util import ( + "fmt" "path" "strings" ) @@ -12,3 +13,7 @@ func JoinUrls(baseUrl string, extensionUrl ...string) string { requestUrl = strings.Replace(requestUrl, "/", "//", 1) return requestUrl } + +func GetErrorMessage(err error) string { + return fmt.Sprintf("%+v", err) +}