Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Error cleanups as reported from golint

  • Loading branch information...
commit 328575d6f3daaa6d5e7ece2cf3dca42d809ad9e8 1 parent 91f4fd6
Dustin Sallings dustin authored
12 conn_pool.go
View
@@ -7,9 +7,7 @@ import (
"github.com/dustin/gomemcached/client"
)
-// Error raised when a connection can't be retrieved from a pool.
-var TimeoutError = errors.New("timeout waiting to build connection")
-var closedPool = errors.New("the pool is closed")
+var errClosedPool = errors.New("the pool is closed")
var errNoPool = errors.New("no pool")
// Default timeout for retrieving a connection from the pool.
@@ -85,7 +83,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (rv *memcached.Client,
select {
case rv, isopen := <-cp.connections:
if !isopen {
- return nil, closedPool
+ return nil, errClosedPool
}
return rv, nil
default:
@@ -99,7 +97,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (rv *memcached.Client,
case rv, isopen := <-cp.connections:
path = "avail1"
if !isopen {
- return nil, closedPool
+ return nil, errClosedPool
}
return rv, nil
case <-t.C:
@@ -110,7 +108,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (rv *memcached.Client,
case rv, isopen := <-cp.connections:
path = "avail2"
if !isopen {
- return nil, closedPool
+ return nil, errClosedPool
}
return rv, nil
case cp.createsem <- true:
@@ -125,7 +123,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (rv *memcached.Client,
}
return rv, err
case <-t.C:
- return nil, TimeoutError
+ return nil, ErrTimeout
}
}
}
28 conn_pool_test.go
View
@@ -22,11 +22,11 @@ func (t testT) Write([]byte) (int, error) {
return 0, io.EOF
}
-var alreadyClosed = errors.New("already closed")
+var errAlreadyClosed = errors.New("already closed")
func (t *testT) Close() error {
if t.closed {
- return alreadyClosed
+ return errAlreadyClosed
}
t.closed = true
return nil
@@ -139,7 +139,7 @@ func TestConnPoolSoonAvailable(t *testing.T) {
var aClient *memcached.Client
for {
sc, err := cp.GetWithTimeout(time.Millisecond)
- if err == TimeoutError {
+ if err == ErrTimeout {
break
}
if err != nil {
@@ -162,7 +162,7 @@ func TestConnPoolSoonAvailable(t *testing.T) {
time.AfterFunc(time.Millisecond, func() { cp.Close() })
sc, err = cp.Get()
- if err != closedPool {
+ if err != errClosedPool {
t.Errorf("Expected a closed pool, got %v/%v", sc, err)
}
@@ -179,7 +179,7 @@ func TestConnPoolClosedFull(t *testing.T) {
for {
sc, err := cp.GetWithTimeout(time.Millisecond)
- if err == TimeoutError {
+ if err == ErrTimeout {
break
}
if err != nil {
@@ -191,7 +191,7 @@ func TestConnPoolClosedFull(t *testing.T) {
time.AfterFunc(2*time.Millisecond, func() { cp.Close() })
sc, err := cp.Get()
- if err != closedPool {
+ if err != errClosedPool {
t.Errorf("Expected closed pool error after closed, got %v/%v", sc, err)
}
}
@@ -207,7 +207,7 @@ func TestConnPoolWaitFull(t *testing.T) {
var aClient *memcached.Client
for {
sc, err := cp.GetWithTimeout(time.Millisecond)
- if err == TimeoutError {
+ if err == ErrTimeout {
break
}
if err != nil {
@@ -236,7 +236,7 @@ func TestConnPoolWaitFailFull(t *testing.T) {
var aClient *memcached.Client
for {
sc, err := cp.GetWithTimeout(time.Millisecond)
- if err == TimeoutError {
+ if err == ErrTimeout {
break
}
if err != nil {
@@ -267,7 +267,7 @@ func TestConnPoolWaitDoubleFailFull(t *testing.T) {
var aClient *memcached.Client
for {
sc, err := cp.GetWithTimeout(time.Millisecond)
- if err == TimeoutError {
+ if err == ErrTimeout {
break
}
if err != nil {
@@ -313,12 +313,12 @@ func TestConnPoolClosed(t *testing.T) {
// This should cause the connection to be closed
cp.Return(c)
- if err = c.Close(); err != alreadyClosed {
+ if err = c.Close(); err != errAlreadyClosed {
t.Errorf("Expected to close connection, wasn't closed (%v)", err)
}
sc, err := cp.Get()
- if err != closedPool {
+ if err != errClosedPool {
t.Errorf("Expected closed pool error after closed, got %v/%v", sc, err)
}
}
@@ -342,7 +342,7 @@ func TestConnPoolCloseWrongPool(t *testing.T) {
cp.Close()
cp.Return(c)
- if err = c.Close(); err != alreadyClosed {
+ if err = c.Close(); err != errAlreadyClosed {
t.Errorf("Expected to close connection, wasn't closed (%v)", err)
}
}
@@ -358,7 +358,7 @@ func TestConnPoolCloseNil(t *testing.T) {
cp = nil
cp.Return(c)
- if err = c.Close(); err != alreadyClosed {
+ if err = c.Close(); err != errAlreadyClosed {
t.Errorf("Expected to close connection, wasn't closed (%v)", err)
}
}
@@ -381,7 +381,7 @@ func TestConnPoolStartTapFeed(t *testing.T) {
cp.Close()
tf, err = cp.StartTapFeed(&args)
- if err != closedPool {
+ if err != errClosedPool {
t.Errorf("Expected a closed pool, got %v/%v", tf, err)
}
}
6 ddocs.go
View
@@ -76,7 +76,7 @@ func (b *Bucket) PutDDoc(docname string, value interface{}) error {
defer res.Body.Close()
if res.StatusCode != 201 {
body, _ := ioutil.ReadAll(res.Body)
- return fmt.Errorf("Error installing view: %v / %s",
+ return fmt.Errorf("error installing view: %v / %s",
res.Status, body)
}
@@ -104,7 +104,7 @@ func (b *Bucket) GetDDoc(docname string, into interface{}) error {
defer res.Body.Close()
if res.StatusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
- return fmt.Errorf("Error reading view: %v / %s",
+ return fmt.Errorf("error reading view: %v / %s",
res.Status, body)
}
@@ -133,7 +133,7 @@ func (b *Bucket) DeleteDDoc(docname string) error {
defer res.Body.Close()
if res.StatusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
- return fmt.Errorf("Error deleting view: %v / %s",
+ return fmt.Errorf("error deleting view: %v / %s",
res.Status, body)
}
2  pools.go
View
@@ -262,7 +262,7 @@ func (b *Bucket) parseURLResponse(path string, out interface{}) error {
return err
}
}
- return errors.New("All nodes failed to respond.")
+ return errors.New("all nodes failed to respond")
}
type basicAuth struct {
2  util.go
View
@@ -43,7 +43,7 @@ func ParseURL(urlStr string) (result *url.URL, err error) {
result, err = url.Parse(urlStr)
if result != nil && result.Scheme == "" {
result = nil
- err = fmt.Errorf("Invalid URL <%s>", urlStr)
+ err = fmt.Errorf("invalid URL <%s>", urlStr)
}
return
}
6 views.go
View
@@ -46,7 +46,7 @@ func (b *Bucket) randomBaseURL() (*url.URL, error) {
node := nodes[nodeNo]
u, err := ParseURL(node.CouchAPIBase)
if err != nil {
- return nil, fmt.Errorf("Config error: Bucket %q node #%d CouchAPIBase=%q: %v",
+ return nil, fmt.Errorf("config error: Bucket %q node #%d CouchAPIBase=%q: %v",
b.Name, nodeNo, node.CouchAPIBase, err)
} else if b.pool != nil {
u.User = b.pool.client.BaseURL.User
@@ -135,14 +135,14 @@ func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{},
res, err := HttpClient.Do(req)
if err != nil {
- return fmt.Errorf("Error starting view req at %v: %v", u, err)
+ return fmt.Errorf("error starting view req at %v: %v", u, err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
bod := make([]byte, 512)
l, _ := res.Body.Read(bod)
- return fmt.Errorf("Error executing view req at %v: %v - %s",
+ return fmt.Errorf("error executing view req at %v: %v - %s",
u, res.Status, bod[:l])
}
Please sign in to comment.
Something went wrong with that request. Please try again.