[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [meek/master] Rewrite 'errors.New(fmt.Sprintf(...)) -> fmt.Errorf(...)'.



commit fe4c33126c8783caa032cd822769c6b49529bed9
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Mon Sep 29 10:05:41 2014 -0700

    Rewrite 'errors.New(fmt.Sprintf(...)) -> fmt.Errorf(...)'.
    
    gofmt -l -w -r 'errors.New(fmt.Sprintf(a)) -> fmt.Errorf(a)' ./appengine ./meek-server ./meek-client-torbrowser ./meek-client ./latencytest ./terminateprocess-buffer
    gofmt -l -w -r 'errors.New(fmt.Sprintf(a, b)) -> fmt.Errorf(a, b)' ./appengine ./meek-server ./meek-client-torbrowser ./meek-client ./latencytest ./terminateprocess-buffer
    gofmt -l -w -r 'errors.New(fmt.Sprintf(a, b, c)) -> fmt.Errorf(a, b, c)' ./appengine ./meek-server ./meek-client-torbrowser ./meek-client ./latencytest ./terminateprocess-buffer
    gofmt -l -w -r 'errors.New(a) -> fmt.Errorf(a)' ./appengine ./meek-server ./meek-client-torbrowser ./meek-client ./latencytest ./terminateprocess-buffer
---
 meek-client/helper.go      |   14 +++++++-------
 meek-client/meek-client.go |    9 ++++-----
 meek-client/proxy.go       |    5 ++---
 meek-server/meek-server.go |    7 +++----
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/meek-client/helper.go b/meek-client/helper.go
index 872f401..37c4615 100644
--- a/meek-client/helper.go
+++ b/meek-client/helper.go
@@ -4,7 +4,6 @@ import (
 	"bytes"
 	"encoding/binary"
 	"encoding/json"
-	"errors"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -55,14 +54,14 @@ func makeProxySpec(u *url.URL) (*ProxySpec, error) {
 
 	// Firefox's nsIProxyInfo doesn't allow credentials.
 	if u.User != nil {
-		return nil, errors.New("proxy URLs with a username or password can't be used with the helper")
+		return nil, fmt.Errorf("proxy URLs with a username or password can't be used with the helper")
 	}
 
 	switch u.Scheme {
 	case "http", "socks5", "socks4a":
 		spec.Type = u.Scheme
 	default:
-		return nil, errors.New("unknown scheme")
+		return nil, fmt.Errorf("unknown scheme")
 	}
 
 	spec.Host, portStr, err = net.SplitHostPort(u.Host)
@@ -70,7 +69,7 @@ func makeProxySpec(u *url.URL) (*ProxySpec, error) {
 		return nil, err
 	}
 	if spec.Host == "" {
-		return nil, errors.New("missing host")
+		return nil, fmt.Errorf("missing host")
 	}
 	port, err = strconv.ParseUint(portStr, 10, 16)
 	if err != nil {
@@ -130,8 +129,9 @@ func roundTripWithHelper(buf []byte, info *RequestInfo) (*http.Response, error)
 		return nil, err
 	}
 	if length > maxHelperResponseLength {
-		return nil, errors.New(fmt.Sprintf("helper's returned data is too big (%d > %d)",
-			length, maxHelperResponseLength))
+		return nil, fmt.Errorf("helper's returned data is too big (%d > %d)",
+			length, maxHelperResponseLength)
+
 	}
 	encResp := make([]byte, length)
 	_, err = io.ReadFull(s, encResp)
@@ -147,7 +147,7 @@ func roundTripWithHelper(buf []byte, info *RequestInfo) (*http.Response, error)
 		return nil, err
 	}
 	if jsonResp.Error != "" {
-		return nil, errors.New(fmt.Sprintf("helper returned error: %s", jsonResp.Error))
+		return nil, fmt.Errorf("helper returned error: %s", jsonResp.Error)
 	}
 
 	// Mock up an HTTP response.
diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index 33861e5..447e785 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -33,7 +33,6 @@ import (
 	"bytes"
 	"crypto/rand"
 	"encoding/base64"
-	"errors"
 	"flag"
 	"fmt"
 	"io"
@@ -147,7 +146,7 @@ again:
 	// returned a status other than 200. Other kinds of errors and success
 	// with 200 always return immediately.
 	if err == nil && resp.StatusCode != http.StatusOK {
-		err = errors.New(fmt.Sprintf("status code was %d, not %d", resp.StatusCode, http.StatusOK))
+		err = fmt.Errorf("status code was %d, not %d", resp.StatusCode, http.StatusOK)
 		if limit > 0 {
 			log.Printf("%s; trying again after %.f seconds (%d)", err, retryDelay.Seconds(), limit)
 			time.Sleep(retryDelay)
@@ -328,7 +327,7 @@ func checkProxyURL(u *url.URL) error {
 	if options.HelperAddr == nil {
 		// Without the helper we only support HTTP proxies.
 		if u.Scheme != "http" {
-			return errors.New(fmt.Sprintf("don't understand proxy URL scheme %q", u.Scheme))
+			return fmt.Errorf("don't understand proxy URL scheme %q", u.Scheme)
 		}
 	} else {
 		// With the helper we can use HTTP and SOCKS (because it is the
@@ -345,10 +344,10 @@ func checkProxyURL(u *url.URL) error {
 		switch u.Scheme {
 		case "http", "socks5", "socks4a":
 		default:
-			return errors.New(fmt.Sprintf("don't understand proxy URL scheme %q", u.Scheme))
+			return fmt.Errorf("don't understand proxy URL scheme %q", u.Scheme)
 		}
 		if u.User != nil {
-			return errors.New("a proxy URL with a username or password can't be used with --helper")
+			return fmt.Errorf("a proxy URL with a username or password can't be used with --helper")
 		}
 	}
 	return nil
diff --git a/meek-client/proxy.go b/meek-client/proxy.go
index 56717a3..8258413 100644
--- a/meek-client/proxy.go
+++ b/meek-client/proxy.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"errors"
 	"fmt"
 	"net/url"
 	"os"
@@ -33,10 +32,10 @@ func PtGetProxyURL() (*url.URL, error) {
 		return nil, err
 	}
 	if u.Scheme == "" {
-		return nil, errors.New("missing scheme")
+		return nil, fmt.Errorf("missing scheme")
 	}
 	if u.Host == "" {
-		return nil, errors.New("missing host")
+		return nil, fmt.Errorf("missing host")
 	}
 	return u, nil
 }
diff --git a/meek-server/meek-server.go b/meek-server/meek-server.go
index 4edf850..44abbb0 100644
--- a/meek-server/meek-server.go
+++ b/meek-server/meek-server.go
@@ -13,7 +13,6 @@ package main
 
 import (
 	"crypto/tls"
-	"errors"
 	"flag"
 	"fmt"
 	"io"
@@ -151,7 +150,7 @@ func transact(session *Session, w http.ResponseWriter, req *http.Request) error
 	body := http.MaxBytesReader(w, req.Body, maxPayloadLength+1)
 	_, err := io.Copy(session.Or, body)
 	if err != nil {
-		return errors.New(fmt.Sprintf("copying body to ORPort: %s", err))
+		return fmt.Errorf("copying body to ORPort: %s", err)
 	}
 
 	buf := make([]byte, maxPayloadLength)
@@ -160,7 +159,7 @@ func transact(session *Session, w http.ResponseWriter, req *http.Request) error
 	if err != nil {
 		if e, ok := err.(net.Error); !ok || !e.Timeout() {
 			httpInternalServerError(w)
-			return errors.New(fmt.Sprintf("reading from ORPort: %s", err))
+			return fmt.Errorf("reading from ORPort: %s", err)
 		}
 	}
 	// log.Printf("read %d bytes from ORPort: %q", n, buf[:n])
@@ -168,7 +167,7 @@ func transact(session *Session, w http.ResponseWriter, req *http.Request) error
 	w.Header().Set("Content-Type", "application/octet-stream")
 	n, err = w.Write(buf[:n])
 	if err != nil {
-		return errors.New(fmt.Sprintf("writing to response: %s", err))
+		return fmt.Errorf("writing to response: %s", err)
 	}
 	// log.Printf("wrote %d bytes to response", n)
 	return nil

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits