Skip to content

Commit

Permalink
Merge pull request #13 from Escape-Technologies/docs/better-errors-logs
Browse files Browse the repository at this point in the history
feat: better errors logs
  • Loading branch information
QuentinN42 authored Sep 18, 2024
2 parents e688f44 + 9a27792 commit 77cae0c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ main
.vscode
.idea
._*
.env
2 changes: 1 addition & 1 deletion cmd/repeater/repeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func setupHTTPClients() string {
if url == "" {
url = "repeater.escape.tech:443"
} else {
logger.Debug("Using custom repeater url: %s\n", url)
logger.Debug("Using custom repeater url: %s", url)
}

insecure := os.Getenv("ESCAPE_REPEATER_INSECURE")
Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetCon(url string) *grpc.ClientConn {
})
creds = grpc.WithTransportCredentials(cred)
}
con, err := grpc.Dial(
con, err := grpc.NewClient(
url,
creds,
grpc.WithDefaultCallOptions(
Expand Down
72 changes: 72 additions & 0 deletions pkg/stream/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package stream

import (
"fmt"
"strings"

"google.golang.org/grpc/status"
)

func invalidClientID(msg string) bool { return msg == "invalid client UUID" }
func noSuchHost(msg string) bool { return strings.Contains(msg, "no such host") }
func timedOut(msg string) bool { return strings.Contains(msg, "i/o timeout") }

func grpcErrorFmt(s *status.Status) []string {
res := []string{}
if s == nil {
return res
}

msg := s.Message()
if invalidClientID(msg) {
res = append(res, "Server rejected your configured client UUID (configuration issue)")
res = append(res, "Check that the ESCAPE_REPEATER_ID environment variable is set correctly")
res = append(res, "Go to https://app.escape.tech/organization/network/ to retrieve your repeaters list")

return res
}

if noSuchHost(msg) {
res = append(res, "Server could not be resolved (DNS issue)")
res = append(res, "If you run inside docker, try passing the --network=host flag")
res = append(res, "From the host machine, check that the server is reachable with nslookup repeater.escape.tech")
}

if timedOut(msg) {
res = append(res, "Timed out connecting to the server (network issue)")
res = append(res, "It may be linked to a firewall missconfiguration or a network issue")
res = append(res, "Check that the documentation about firewall configuration https://docs.escape.tech/platform/enterprise/repeater#configure-your-firewall")
res = append(res, "You can also try to run tracepath or tcptraceroute to check where the connection is blocked")
}

res = append(res, "If you need more help to debug this issue, please contact the support team with the result of a curl -v https://repeater.escape.tech")
return res
}

func extractWhyStreamCreateError(err error) []string {
res := []string{}
if err == nil {
return res
}

res = append(res, fmt.Sprintf("Error creating stream: %v", err))
if s, ok := status.FromError(err); ok {
res = append(res, grpcErrorFmt(s)...)
}

return res
}

func extractWhyRecvError(err error) []string {
if err == nil {
return []string{}
}
res := []string{}

res = append(res, fmt.Sprintf("Error receiving data: %v", err))
if s, ok := status.FromError(err); ok {
res = append(res, grpcErrorFmt(s)...)
}

return res
}
8 changes: 6 additions & 2 deletions pkg/stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func ConnectAndRun(url, repeaterId string, isConnected *atomic.Bool) (hasConnect
stream, closer, err := grpc.Stream(url, repeaterId)
defer closer()
if err != nil {
logger.Error("Error creating stream: %v", err)
for _, why := range extractWhyStreamCreateError(err) {
logger.Error(why) //nolint:govet
}
return false
}
logger.Info("Repeater connected to server...")
Expand Down Expand Up @@ -61,7 +63,9 @@ func ConnectAndRun(url, repeaterId string, isConnected *atomic.Bool) (hasConnect
for {
req, err := stream.Recv()
if err != nil {
logger.Error("Error receiving: %v", err)
for _, why := range extractWhyRecvError(err) {
logger.Error(why) //nolint:govet
}
return true
}
logger.Info("Received incoming stream (%d)", req.Correlation)
Expand Down

0 comments on commit 77cae0c

Please sign in to comment.