Skip to content

Commit

Permalink
fix: log stacktrace with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ViRb3 committed Apr 16, 2020
1 parent e331275 commit ebe56b3
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cloudflare/util/util.go
@@ -1,7 +1,7 @@
package util

import (
"errors"
"github.com/pkg/errors"
"time"
"wgcf/cloudflare/structs/resp"
)
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/util/web.go
Expand Up @@ -2,8 +2,8 @@ package util

import (
"encoding/json"
"errors"
"fmt"
"github.com/pkg/errors"
"io"
"io/ioutil"
"net/http"
Expand Down
5 changes: 3 additions & 2 deletions 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"
)

Expand All @@ -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))
}
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/register/register.go
@@ -1,16 +1,17 @@
package register

import (
"errors"
"fmt"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"wgcf/cloudflare/api"
"wgcf/cloudflare/url"
. "wgcf/cmd/util"
"wgcf/config"
"wgcf/util"
"wgcf/wireguard"
)

Expand All @@ -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))
}
},
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Expand Up @@ -9,22 +9,23 @@ import (
"wgcf/cmd/status"
"wgcf/cmd/trace"
"wgcf/cmd/update"
"wgcf/cmd/util"
. "wgcf/cmd/util"
"wgcf/config"
"wgcf/util"
)

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))
}
},
}
Expand Down
5 changes: 3 additions & 2 deletions 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"
Expand All @@ -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))
}
},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/trace/trace.go
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"strings"
. "wgcf/cmd/util"
"wgcf/util"
)

var shortMsg = "Prints trace information about the current internet connection"
Expand All @@ -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))
}
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/update/update.go
@@ -1,14 +1,15 @@
package update

import (
"errors"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"wgcf/cloudflare/api"
"wgcf/cloudflare/structs/resp"
. "wgcf/cmd/util"
"wgcf/config"
"wgcf/util"
)

var deviceName string
Expand All @@ -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))
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/util.go
@@ -1,7 +1,7 @@
package util

import (
"errors"
"github.com/pkg/errors"
"github.com/spf13/viper"
"log"
"strings"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -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))
}
}
5 changes: 5 additions & 0 deletions util/url.go
@@ -1,6 +1,7 @@
package util

import (
"fmt"
"path"
"strings"
)
Expand All @@ -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)
}

0 comments on commit ebe56b3

Please sign in to comment.