From 74d54804a847824ebb602b742906eedd89d80970 Mon Sep 17 00:00:00 2001 From: Gabor Retvari Date: Thu, 28 Nov 2024 14:24:34 +0100 Subject: [PATCH] chore: Improve error message consistency --- cmd/turncat/main.go | 8 ++++---- internal/object/admin.go | 2 +- internal/object/errors.go | 2 +- internal/resolver/mock.go | 2 +- internal/resolver/resolver.go | 6 +++--- internal/util/endpoint.go | 6 +++--- pkg/apis/v1/auth.go | 3 +-- pkg/apis/v1/errors.go | 8 ++++---- pkg/config/client/client.go | 4 ++-- pkg/config/client/file_client.go | 12 ++++++------ pkg/config/client/k8s_client.go | 14 +++++++------- pkg/whipconn/dialer.go | 26 +++++++++++++------------- pkg/whipconn/listener.go | 18 +++++++++--------- relay.go | 8 ++++---- turncat.go | 16 ++++++++-------- uri.go | 4 ++-- 16 files changed, 69 insertions(+), 70 deletions(-) diff --git a/cmd/turncat/main.go b/cmd/turncat/main.go index 69f63cc1..93c8349e 100644 --- a/cmd/turncat/main.go +++ b/cmd/turncat/main.go @@ -146,14 +146,14 @@ func getStunnerConf(uri string) (*stnrv1.StunnerConfig, error) { case "k8s": conf, err := getStunnerConfFromK8s(def) if err != nil { - return nil, fmt.Errorf("Could not read running STUNner configuration from "+ + return nil, fmt.Errorf("could not read running STUNner configuration from "+ "Kubernetes: %w", err) } return conf, nil case "turn": conf, err := getStunnerConfFromCLI(def) if err != nil { - return nil, fmt.Errorf("Could not generate STUNner configuration from "+ + return nil, fmt.Errorf("could not generate STUNner configuration from "+ "URI %q: %w", uri, err) } return conf, nil @@ -237,11 +237,11 @@ func getStunnerConfFromCLI(def string) (*stnrv1.StunnerConfig, error) { u, err := stunner.ParseUri(uri) if err != nil { - return nil, fmt.Errorf("Invalid STUNner URI %q: %s", uri, err) + return nil, fmt.Errorf("invalid STUNner URI %q: %s", uri, err) } if u.Username == "" || u.Password == "" { - return nil, fmt.Errorf("Username/password must be set: '%s'", uri) + return nil, fmt.Errorf("username/password must be set: '%s'", uri) } conf.Listeners[0].PublicAddr = u.Address diff --git a/internal/object/admin.go b/internal/object/admin.go index 418449c2..9bb5c7eb 100644 --- a/internal/object/admin.go +++ b/internal/object/admin.go @@ -198,7 +198,7 @@ func (a *Admin) reconcileMetrics(req *stnrv1.AdminConfig) error { a.log.Tracef("closing metrics server at %s", mEndpoint) if err := a.metricsServer.Shutdown(context.Background()); err != nil { - return fmt.Errorf("error stopping metrics server at %s: %w", + return fmt.Errorf("failed to stop metrics server at %s: %w", mEndpoint, err) } a.metricsServer = nil diff --git a/internal/object/errors.go b/internal/object/errors.go index c7ee7542..2b984680 100644 --- a/internal/object/errors.go +++ b/internal/object/errors.go @@ -4,5 +4,5 @@ import "errors" var ( // ErrRestartRequired indicates that an object needs to be restarted for reconciliation. - ErrRestartRequired = errors.New("Restart required") + ErrRestartRequired = errors.New("restart required") ) diff --git a/internal/resolver/mock.go b/internal/resolver/mock.go index d25aa437..2d2960a0 100644 --- a/internal/resolver/mock.go +++ b/internal/resolver/mock.go @@ -63,5 +63,5 @@ func (m *MockResolver) Lookup(domain string) ([]net.IP, error) { } } - return []net.IP{}, fmt.Errorf("Host %q not found: 3(NXDOMAIN)", domain) + return []net.IP{}, fmt.Errorf("host %q not found: 3(NXDOMAIN)", domain) } diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 7b7a305c..6b1f8328 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -119,7 +119,7 @@ func doResolve(e *serviceEntry) error { if e.cname == "" { cname, err := e.resolver.LookupCNAME(e.ctx, e.domain) if err != nil { - return fmt.Errorf("Cannot resolve CNAME for domain %q: %s", + return fmt.Errorf("failed to resolve CNAME for domain %q: %s", e.domain, err.Error()) } e.cname = cname @@ -127,7 +127,7 @@ func doResolve(e *serviceEntry) error { hosts, err := e.resolver.LookupHost(e.ctx, e.domain) if err != nil { - return fmt.Errorf("Cannot resolve CNAME for domain %q: %s", + return fmt.Errorf("failed to resolve CNAME for domain %q: %s", e.domain, err.Error()) } @@ -175,7 +175,7 @@ func (r *dnsResolverImpl) Lookup(domain string) ([]net.IP, error) { e, found := r.register[domain] if !found { - return []net.IP{}, fmt.Errorf("Unknown domain name: %q", domain) + return []net.IP{}, fmt.Errorf("unknown domain name: %q", domain) } e.lock.RLock() diff --git a/internal/util/endpoint.go b/internal/util/endpoint.go index f33b466e..9d5d1961 100644 --- a/internal/util/endpoint.go +++ b/internal/util/endpoint.go @@ -33,11 +33,11 @@ func ParseEndpoint(ep string) (*Endpoint, error) { } else { port, err = strconv.Atoi(m[2]) if err != nil { - return nil, fmt.Errorf("Invalid port in endpoint %q: %w", ep, err) + return nil, fmt.Errorf("invalid port in endpoint %q: %w", ep, err) } endPort, err = strconv.Atoi(m[3]) if err != nil { - return nil, fmt.Errorf("Invalid end-port in endpoint %q: %w", ep, err) + return nil, fmt.Errorf("invalid end-port in endpoint %q: %w", ep, err) } cidr = m[1] hasPort = true @@ -56,7 +56,7 @@ func ParseEndpoint(ep string) (*Endpoint, error) { // convert to an actual prefix _, ipnet, err := net.ParseCIDR(cidr) if err != nil { - return nil, fmt.Errorf("Invalid endpoint %q: %w", ep, err) + return nil, fmt.Errorf("invalid endpoint %q: %w", ep, err) } return &Endpoint{ diff --git a/pkg/apis/v1/auth.go b/pkg/apis/v1/auth.go index 4f37c5a3..a46cba87 100644 --- a/pkg/apis/v1/auth.go +++ b/pkg/apis/v1/auth.go @@ -44,8 +44,7 @@ func (req *AuthConfig) Validate() error { case AuthTypeEphemeral: _, secretFound := req.Credentials["secret"] if !secretFound { - return fmt.Errorf("cannot handle auth config for type %s: invalid secret", - atype.String()) + return fmt.Errorf("no secret found in %s auth config", atype.String()) } default: return fmt.Errorf("invalid authentication type %q", req.Type) diff --git a/pkg/apis/v1/errors.go b/pkg/apis/v1/errors.go index a9b4f71b..2b5862d3 100644 --- a/pkg/apis/v1/errors.go +++ b/pkg/apis/v1/errors.go @@ -7,10 +7,10 @@ import ( ) var ( - ErrInvalidConf = errors.New("Invalid configuration") - ErrNoSuchListener = errors.New("No such listener") - ErrNoSuchCluster = errors.New("No such cluster") - // ErrInvalidRoute = errors.New("Invalid route") + ErrInvalidConf = errors.New("invalid configuration") + ErrNoSuchListener = errors.New("no such listener") + ErrNoSuchCluster = errors.New("no such cluster") + // ErrInvalidRoute = errors.New("invalid route") ) type ErrRestarted struct { diff --git a/pkg/config/client/client.go b/pkg/config/client/client.go index d54a843d..9becd437 100644 --- a/pkg/config/client/client.go +++ b/pkg/config/client/client.go @@ -11,7 +11,7 @@ import ( "github.com/pion/logging" ) -var errFileTruncated = errors.New("Zero-length config file") +var errFileTruncated = errors.New("zero-length config file") var ( // Send pings to the CDS server with this period. Must be less than PongWait. @@ -49,7 +49,7 @@ type Client interface { func New(origin string, id string, logger logging.LoggerFactory) (Client, error) { u, err := getURI(origin) if err != nil { - return nil, fmt.Errorf("could not parse config origin URI %q: %w", origin, err) + return nil, fmt.Errorf("failed to parse config origin URI %q: %w", origin, err) } switch strings.ToLower(u.Scheme) { diff --git a/pkg/config/client/file_client.go b/pkg/config/client/file_client.go index 0ead3bfc..adb0e8d8 100644 --- a/pkg/config/client/file_client.go +++ b/pkg/config/client/file_client.go @@ -45,7 +45,7 @@ func (w *ConfigFileClient) String() string { func (w *ConfigFileClient) Load() (*stnrv1.StunnerConfig, error) { b, err := os.ReadFile(w.configFile) if err != nil { - return nil, fmt.Errorf("could not read config file %q: %s", w.configFile, err.Error()) + return nil, fmt.Errorf("failed to read config file %q: %s", w.configFile, err.Error()) } if len(b) == 0 { @@ -54,7 +54,7 @@ func (w *ConfigFileClient) Load() (*stnrv1.StunnerConfig, error) { c, err := ParseConfig(b) if err != nil { - return nil, fmt.Errorf("could not parse config: %w", err) + return nil, fmt.Errorf("failed to parse config: %w", err) } if err := c.Validate(); err != nil { @@ -128,7 +128,7 @@ func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerCo case e, ok := <-watcher.Events: if !ok { - return errors.New("Config watcher received invalid event") + return errors.New("config watcher received invalid event") } w.log.Debugf("Received watch event: %s", e.String()) @@ -139,7 +139,7 @@ func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerCo config, err.Error()) } - return fmt.Errorf("Config file deleted %q, disabling watcher", e.Op.String()) + return fmt.Errorf("config file deleted %q, disabling watcher", e.Op.String()) } if !e.Has(fsnotify.Write) { @@ -178,7 +178,7 @@ func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerCo case err, ok := <-watcher.Errors: if !ok { - return errors.New("Config watcher error handler received invalid error") + return errors.New("config watcher error handler received invalid error") } if err := watcher.Remove(config); err != nil { @@ -186,7 +186,7 @@ func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerCo config, err.Error()) } - return fmt.Errorf("Config watcher error, deactivating: %w", err) + return fmt.Errorf("config watcher error, deactivating: %w", err) } } } diff --git a/pkg/config/client/k8s_client.go b/pkg/config/client/k8s_client.go index f32db5a7..c18752a1 100644 --- a/pkg/config/client/k8s_client.go +++ b/pkg/config/client/k8s_client.go @@ -237,7 +237,7 @@ func DiscoverK8sStunnerdPods(ctx context.Context, k8sFlags *cliopt.ConfigFlags, appLabel, err := labels.NewRequirement(stnrv1.DefaultAppLabelKey, selection.Equals, []string{stnrv1.DefaultAppLabelValue}) if err != nil { - return ps, fmt.Errorf("cannot create app label selector: %w", err) + return ps, fmt.Errorf("failed to create app label selector: %w", err) } selector = selector.Add(*appLabel) @@ -245,7 +245,7 @@ func DiscoverK8sStunnerdPods(ctx context.Context, k8sFlags *cliopt.ConfigFlags, nsLabel, err := labels.NewRequirement(stnrv1.DefaultRelatedGatewayNamespace, selection.Equals, []string{gwNs}) if err != nil { - return ps, fmt.Errorf("cannot create namespace label selector: %w", err) + return ps, fmt.Errorf("failed to create namespace label selector: %w", err) } selector = selector.Add(*nsLabel) @@ -253,7 +253,7 @@ func DiscoverK8sStunnerdPods(ctx context.Context, k8sFlags *cliopt.ConfigFlags, gwLabel, err := labels.NewRequirement(stnrv1.DefaultRelatedGatewayKey, selection.Equals, []string{gw}) if err != nil { - return ps, fmt.Errorf("cannot create namespace label selector: %w", err) + return ps, fmt.Errorf("failed to create namespace label selector: %w", err) } selector = selector.Add(*gwLabel) } @@ -344,7 +344,7 @@ func DiscoverK8sAuthServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, au LabelSelector: label, }) if err != nil { - return PodInfo{}, fmt.Errorf("Failed to query Kubernetes API server: %w", err) + return PodInfo{}, fmt.Errorf("failed to query Kubernetes API server: %w", err) } if len(pods.Items) == 0 { @@ -376,7 +376,7 @@ func (d *PodConnector) portfwd(ctx context.Context, pod *corev1.Pod, port int) ( d.log.Debugf("Creating a SPDY stream to API server using URL %q", req.URL().String()) transport, upgrader, err := spdy.RoundTripperFor(d.config) if err != nil { - return PodInfo{}, fmt.Errorf("error getting transport/upgrader from restconfig: %w", err) + return PodInfo{}, fmt.Errorf("failed to get transport/upgrader from restconfig: %w", err) } dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, http.MethodPost, req.URL()) @@ -387,12 +387,12 @@ func (d *PodConnector) portfwd(ctx context.Context, pod *corev1.Pod, port int) ( out, errOut := new(bytes.Buffer), new(bytes.Buffer) fw, err := portforward.New(dialer, []string{remoteAddr}, stopChan, readyChan, out, errOut) if err != nil { - return PodInfo{}, fmt.Errorf("Error creating port-forwarder: %w", err) + return PodInfo{}, fmt.Errorf("failed to create port-forwarder: %w", err) } go func() { if err := fw.ForwardPorts(); err != nil { - d.log.Errorf("Error setting up port-forwarder: %s", err.Error()) + d.log.Errorf("failed to set up port-forwarder: %s", err.Error()) os.Exit(1) } }() diff --git a/pkg/whipconn/dialer.go b/pkg/whipconn/dialer.go index ca2252d0..c447a945 100644 --- a/pkg/whipconn/dialer.go +++ b/pkg/whipconn/dialer.go @@ -49,13 +49,13 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) ICETransportPolicy: d.config.ICETransportPolicy, }) if err != nil { - return nil, fmt.Errorf("Failed to create PeerConnection: %w", err) + return nil, fmt.Errorf("failed to create PeerConnection: %w", err) } d.log.Trace("Creating DataChannel") dataChannel, err := peerConn.CreateDataChannel("whipconn", nil) if err != nil { - return nil, fmt.Errorf("Failed to create DataChannel: %w", err) + return nil, fmt.Errorf("failed to create DataChannel: %w", err) } conn := &dialerConn{ @@ -77,7 +77,7 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) raw, err := dataChannel.Detach() if err != nil { - errCh <- fmt.Errorf("Failed to detach DataChannel: %w", err) + errCh <- fmt.Errorf("failed to detach DataChannel: %w", err) } conn.dataConn = raw @@ -95,13 +95,13 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) offer, err := peerConn.CreateOffer(nil) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Failed to create offer: %w", err) + return nil, fmt.Errorf("failed to create offer: %w", err) } err = peerConn.SetLocalDescription(offer) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Failed to set local SDP (Offer): %w", err) + return nil, fmt.Errorf("failed to set local SDP (Offer): %w", err) } // Block until ICE Gathering is complete, disabling trickle ICE @@ -118,7 +118,7 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) makeURL(addr, d.config.Endpoint).String(), bytes.NewBuffer(sdp)) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Unexpected error building HTTP request: %w", err) + return nil, fmt.Errorf("unexpected error building HTTP request: %w", err) } req.Header.Add("Content-Type", "application/sdp") @@ -129,7 +129,7 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) resp, err := http.DefaultClient.Do(req) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Failed to POST WHIP request: %w", err) + return nil, fmt.Errorf("failed to POST WHIP request: %w", err) } d.log.Tracef("Received POST response with status code: %d", resp.StatusCode) @@ -142,14 +142,14 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) body, err := io.ReadAll(resp.Body) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Failed to read HTTP response body: %w", err) + return nil, fmt.Errorf("failed to read HTTP response body: %w", err) } defer resp.Body.Close() resourceId := resp.Header.Get("Location") if resourceId == "" { conn.Close() //nolint - return nil, errors.New("Empty resource id in POST response") + return nil, errors.New("empty resource id in POST response") } conn.resourceId = resourceId @@ -160,7 +160,7 @@ func (d *Dialer) DialContext(ctx context.Context, addr string) (net.Conn, error) err = peerConn.SetRemoteDescription(answer) if err != nil { conn.Close() //nolint - return nil, fmt.Errorf("Failed to set remote SDP (Answer): %w", err) + return nil, fmt.Errorf("failed to set remote SDP (Answer): %w", err) } // Waiting for the connection or errors surfaced from the callbacks @@ -198,19 +198,19 @@ func (c *dialerConn) Close() error { uri := makeURL(c.addr, makeResourceURL(c.dialer.config.Endpoint, c.resourceId)) req, err := http.NewRequest("DELETE", uri.String(), nil) if err != nil { - return fmt.Errorf("Unexpected error building http request: %w", err) + return fmt.Errorf("unexpected error building http request: %w", err) } if c.dialer.config.Token != "" { req.Header.Add("Authorization", "Bearer "+c.dialer.config.Token) } if _, err = http.DefaultClient.Do(req); err != nil { - return fmt.Errorf("Failed WHIP DELETE request: %w", err) + return fmt.Errorf("failed WHIP DELETE request: %w", err) } // Close the peerconnection if err := c.peerConn.Close(); err != nil { - return fmt.Errorf("Failed to close PeerConnection: %w", err) + return fmt.Errorf("failed to close PeerConnection: %w", err) } return nil diff --git a/pkg/whipconn/listener.go b/pkg/whipconn/listener.go index c9169a1f..86be4447 100644 --- a/pkg/whipconn/listener.go +++ b/pkg/whipconn/listener.go @@ -68,7 +68,7 @@ func NewListener(addr string, config Config, logger logging.LoggerFactory) (*Lis c, err := net.Listen("tcp", addr) if err != nil { - return nil, fmt.Errorf("Cannot open WHIP server socket on %s: %w", addr, err) + return nil, fmt.Errorf("failed to open WHIP server socket on %s: %w", addr, err) } l.server = &http.Server{Addr: addr, Handler: mux} go func() { @@ -135,7 +135,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { // Check bearer token if l.config.Token != "" { if token := r.Header.Get("Authorization"); token != "Bearer "+l.config.Token { - err := fmt.Errorf("Unauthorized WHIP request from client %s", r.RemoteAddr) + err := fmt.Errorf("unauthorized WHIP request from client %s", r.RemoteAddr) l.errCh <- err http.Error(w, err.Error(), http.StatusUnauthorized) return @@ -143,7 +143,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { } if ctype := r.Header.Get("Content-Type"); ctype != "application/sdp" { - err := fmt.Errorf("Invalid WHIP request from client %s, expected Content-Type=application/sdp", + err := fmt.Errorf("invalid WHIP request from client %s, expected Content-Type=application/sdp", r.RemoteAddr) l.errCh <- err http.Error(w, err.Error(), http.StatusBadRequest) @@ -154,7 +154,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { offer, err := io.ReadAll(r.Body) defer r.Body.Close() if err != nil { - l.errCh <- fmt.Errorf("Failed to read WHIP request body: %w", err) + l.errCh <- fmt.Errorf("failed to read WHIP request body: %w", err) return } @@ -169,7 +169,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { ICETransportPolicy: l.config.ICETransportPolicy, }) if err != nil { - l.errCh <- fmt.Errorf("Failed to create a PeerConnection: %w", err) + l.errCh <- fmt.Errorf("failed to create a PeerConnection: %w", err) return } conn.peerConn = peerConn @@ -192,7 +192,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { raw, dErr := dataChannel.Detach() if dErr != nil { - l.errCh <- fmt.Errorf("Failed to detach DataChannel: %w", err) + l.errCh <- fmt.Errorf("failed to detach DataChannel: %w", err) return } conn.dataConn = raw @@ -208,7 +208,7 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { Type: webrtc.SDPTypeOffer, SDP: string(offer), }); err != nil { - l.errCh <- fmt.Errorf("Failed to set remote SDP (Offer): %w", err) + l.errCh <- fmt.Errorf("failed to set remote SDP (Offer): %w", err) return } @@ -218,10 +218,10 @@ func (l *Listener) whipRequestHandler(w http.ResponseWriter, r *http.Request) { // Create answer answer, err := peerConn.CreateAnswer(nil) if err != nil { - l.errCh <- fmt.Errorf("Failed to create SDP (Answer): %w", err) + l.errCh <- fmt.Errorf("failed to create SDP (Answer): %w", err) return } else if err = peerConn.SetLocalDescription(answer); err != nil { - l.errCh <- fmt.Errorf("Failed to set local SDP (Answer): %w", err) + l.errCh <- fmt.Errorf("failed to set local SDP (Answer): %w", err) return } diff --git a/relay.go b/relay.go index c93a1f1f..fa9e3036 100644 --- a/relay.go +++ b/relay.go @@ -21,13 +21,13 @@ import ( const ClusterCacheSize = 512 var ( - errNilConn = errors.New("Cannot allocate relay connection") - errTodo = errors.New("Relay to Net.Conn not implemented") + errNilConn = errors.New("cannot allocate relay connection") + errTodo = errors.New("relay to Net.Conn not implemented") ) var ( - ErrPortProhibited = errors.New("Peer port administratively prohibited") - ErrInvalidPeerProtocol = errors.New("Unknown peer transport protocol") + ErrPortProhibited = errors.New("peer port administratively prohibited") + ErrInvalidPeerProtocol = errors.New("unknown peer transport protocol") ) type PortRangeChecker = func(addr net.Addr) (*object.Cluster, bool) diff --git a/turncat.go b/turncat.go index b8872d0d..7dd9dcce 100644 --- a/turncat.go +++ b/turncat.go @@ -241,7 +241,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { user, passwd, errAuth := t.authGen() if errAuth != nil { - return nil, fmt.Errorf("Cannot generate username/password pair for client %s:%s: %s", + return nil, fmt.Errorf("failed to generate username/password pair for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), errAuth) } @@ -251,14 +251,14 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { case "turn-udp": t, err := net.ListenPacket(t.serverAddr.Network(), "0.0.0.0:0") if err != nil { - return nil, fmt.Errorf("cannot allocate TURN listening packet socket for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN listening packet socket for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), err) } turnConn = t case "turn-tcp": c, err := net.Dial(t.serverAddr.Network(), t.serverAddr.String()) if err != nil { - return nil, fmt.Errorf("cannot allocate TURN socket for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN socket for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), err) } turnConn = turn.NewSTUNConn(c) @@ -271,7 +271,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { InsecureSkipVerify: t.insecure, }) if err != nil { - return nil, fmt.Errorf("cannot allocate TURN/TLS socket for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN/TLS socket for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), err) } turnConn = turn.NewSTUNConn(c) @@ -283,7 +283,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { InsecureSkipVerify: t.insecure, }) if err != nil { - return nil, fmt.Errorf("cannot allocate TURN/DTLS socket for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN/DTLS socket for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), err) } turnConn = turn.NewSTUNConn(conn) @@ -303,7 +303,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { }) if err != nil { turnConn.Close() - return nil, fmt.Errorf("Cannot allocate TURN client for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN client for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), err) } conn.turnConn = turnConn @@ -311,7 +311,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { // Start the TURN client if err = turnClient.Listen(); err != nil { turnConn.Close() - return nil, fmt.Errorf("cannot listen on TURN client: %s", err) + return nil, fmt.Errorf("failed to listen on TURN client: %s", err) } conn.turnClient = turnClient @@ -320,7 +320,7 @@ func (t *Turncat) newConnection(clientConn net.Conn) (*connection, error) { serverConn, serverErr := turnClient.Allocate() if serverErr != nil { turnClient.Close() - return nil, fmt.Errorf("could not allocate new TURN relay transport for client %s:%s: %s", + return nil, fmt.Errorf("failed to allocate TURN relay transport for client %s:%s: %s", clientAddr.Network(), clientAddr.String(), serverErr.Error()) } conn.serverConn = serverConn diff --git a/uri.go b/uri.go index d4ac5817..3258419e 100644 --- a/uri.go +++ b/uri.go @@ -34,7 +34,7 @@ func ParseUri(uri string) (*StunnerUri, error) { u, err := url.Parse(uri) if err != nil { - return nil, fmt.Errorf("Invalid URI '%s': %s", uri, err) + return nil, fmt.Errorf("invalid URI '%s': %s", uri, err) } s.Address = u.Hostname() @@ -163,5 +163,5 @@ func getStunnerProtoForURI(u *url.URL) (string, error) { return "TURN-TLS", nil } - return "", fmt.Errorf("Invalid scheme/protocol in URI %q", u.String()) + return "", fmt.Errorf("invalid scheme/protocol in URI %q", u.String()) }