Skip to content

Commit

Permalink
Fix errorlint across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Oct 29, 2020
1 parent dad610d commit db93d07
Show file tree
Hide file tree
Showing 32 changed files with 140 additions and 64 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ func parseEndpoint(endpoint string, tls bool) (*url.URL, error) {
case "http", "https", "tcp":
_, port, err := net.SplitHostPort(u.Host)
if err != nil {
if e, ok := err.(*net.AddrError); ok {
var e *net.AddrError
if errors.As(err, &e) {
if e.Err == "missing port in address" {
return u, nil
}
Expand Down
4 changes: 3 additions & 1 deletion container_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"encoding/json"
"errors"
"net/http"
)

Expand All @@ -12,7 +13,8 @@ func (c *Client) ContainerChanges(id string) ([]Change, error) {
path := "/containers/" + id + "/changes"
resp, err := c.do(http.MethodGet, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: id}
}
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion container_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"errors"
"net/http"
)

Expand Down Expand Up @@ -30,7 +31,8 @@ func (c *Client) CommitContainer(opts CommitContainerOptions) (*Image, error) {
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.Container}
}
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion container_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error {
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.Container}
}
return err
Expand Down
3 changes: 2 additions & 1 deletion container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error
},
)

if e, ok := err.(*Error); ok {
var e *Error
if errors.As(err, &e) {
if e.Status == http.StatusNotFound && strings.Contains(e.Message, "No such image") {
return nil, ErrNoSuchImage
}
Expand Down
4 changes: 3 additions & 1 deletion container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"errors"
"net/http"
)

Expand Down Expand Up @@ -31,7 +32,8 @@ func (c *Client) InspectContainerWithOptions(opts InspectContainerOptions) (*Con
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.ID}
}
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions container_kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"
"errors"
"net/http"
)

Expand All @@ -27,8 +28,8 @@ func (c *Client) KillContainer(opts KillContainerOptions) error {
path := "/containers/" + opts.ID + "/kill" + "?" + queryString(opts)
resp, err := c.do(http.MethodPost, path, doOptions{context: opts.Context})
if err != nil {
e, ok := err.(*Error)
if !ok {
var e *Error
if !errors.As(err, &e) {
return err
}
switch e.Status {
Expand Down
4 changes: 3 additions & 1 deletion container_pause.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docker

import (
"errors"
"fmt"
"net/http"
)
Expand All @@ -12,7 +13,8 @@ func (c *Client) PauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/pause", id)
resp, err := c.do(http.MethodPost, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand Down
4 changes: 3 additions & 1 deletion container_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"
"errors"
"net/http"
)

Expand Down Expand Up @@ -29,7 +30,8 @@ func (c *Client) RemoveContainer(opts RemoveContainerOptions) error {
path := "/containers/" + opts.ID + "?" + queryString(opts)
resp, err := c.do(http.MethodDelete, path, doOptions{context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.ID}
}
return err
Expand Down
4 changes: 3 additions & 1 deletion container_restart.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docker

import (
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -52,7 +53,8 @@ func (c *Client) RestartContainer(id string, timeout uint) error {
path := fmt.Sprintf("/containers/%s/restart?t=%d", id, timeout)
resp, err := c.do(http.MethodPost, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand Down
4 changes: 3 additions & 1 deletion container_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"
"errors"
"net/http"
)

Expand Down Expand Up @@ -43,7 +44,8 @@ func (c *Client) startContainer(id string, hostConfig *HostConfig, opts doOption
}
resp, err := c.do(http.MethodPost, path, opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id, Err: err}
}
return err
Expand Down
7 changes: 4 additions & 3 deletions container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -175,8 +176,8 @@ func (c *Client) Stats(opts StatsOptions) (retErr error) {
reqSent: reqSent,
})
if err != nil {
dockerError, ok := err.(*Error)
if ok {
var dockerError *Error
if errors.As(err, &dockerError) {
if dockerError.Status == http.StatusNotFound {
err = &NoSuchContainer{ID: opts.ID}
}
Expand All @@ -203,7 +204,7 @@ func (c *Client) Stats(opts StatsOptions) (retErr error) {
decoder := json.NewDecoder(readCloser)
stats := new(Stats)
<-reqSent
for err := decoder.Decode(stats); err != io.EOF; err = decoder.Decode(stats) {
for err := decoder.Decode(stats); !errors.Is(err, io.EOF); err = decoder.Decode(stats) {
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"
"errors"
"fmt"
"net/http"
)
Expand All @@ -28,7 +29,8 @@ func (c *Client) stopContainer(id string, timeout uint, opts doOptions) error {
path := fmt.Sprintf("/containers/%s/stop?t=%d", id, timeout)
resp, err := c.do(http.MethodPost, path, opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand Down
4 changes: 3 additions & 1 deletion container_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand All @@ -27,7 +28,8 @@ func (c *Client) TopContainer(id string, psArgs string) (TopResult, error) {
path := fmt.Sprintf("/containers/%s/top%s", id, args)
resp, err := c.do(http.MethodGet, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return result, &NoSuchContainer{ID: id}
}
return result, err
Expand Down
4 changes: 3 additions & 1 deletion container_unpause.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docker

import (
"errors"
"fmt"
"net/http"
)
Expand All @@ -12,7 +13,8 @@ func (c *Client) UnpauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/unpause", id)
resp, err := c.do(http.MethodPost, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand Down
4 changes: 3 additions & 1 deletion container_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"errors"
"net/http"
)

Expand All @@ -27,7 +28,8 @@ func (c *Client) WaitContainerWithContext(id string, ctx context.Context) (int,
func (c *Client) waitContainer(id string, opts doOptions) (int, error) {
resp, err := c.do(http.MethodPost, "/containers/"+id+"/wait", opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return 0, &NoSuchContainer{ID: id}
}
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestDecode(t *testing.T) {
[]string{"PATH=/usr/bin:/bin", "containers=54", `wat=["123","345"]`},
"",
},
{"}}", nil, "invalid character '}' looking for beginning of value"},
{"}}", nil, "json: invalid character '}' looking for beginning of value"},
{`{}`, nil, ""},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (eventState *eventMonitoringState) monitorEvents(c *Client) {
eventState.updateLastSeen(ev)
eventState.sendEvent(ev)
case err = <-eventState.errC:
if err == ErrNoListeners {
if errors.Is(err, ErrNoListeners) {
eventState.disableEventMonitoring()
return
} else if err != nil {
Expand Down Expand Up @@ -346,7 +346,7 @@ func (c *Client) eventHijack(startTime int64, eventChan chan *APIEvents, errChan
for {
var event APIEvents
if err = decoder.Decode(&event); err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
c.eventMonitor.RLock()
if c.eventMonitor.enabled && c.eventMonitor.C == eventChan {
// Signal that we're exiting.
Expand Down
9 changes: 6 additions & 3 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (c *Client) CreateExec(opts CreateExecOptions) (*Exec, error) {
path := fmt.Sprintf("/containers/%s/exec", opts.Container)
resp, err := c.do(http.MethodPost, path, doOptions{data: opts, context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.Container}
}
return nil, err
Expand Down Expand Up @@ -122,7 +123,8 @@ func (c *Client) StartExecNonBlocking(id string, opts StartExecOptions) (CloseWa
if opts.Detach {
resp, err := c.do(http.MethodPost, path, doOptions{data: opts, context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchExec{ID: id}
}
return nil, err
Expand Down Expand Up @@ -195,7 +197,8 @@ func (c *Client) InspectExec(id string) (*ExecInspect, error) {
path := fmt.Sprintf("/exec/%s/json", id)
resp, err := c.do(http.MethodGet, path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchExec{ID: id}
}
return nil, err
Expand Down
12 changes: 8 additions & 4 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ type ImageHistory struct {
func (c *Client) ImageHistory(name string) ([]ImageHistory, error) {
resp, err := c.do(http.MethodGet, "/images/"+name+"/history", doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
return nil, err
Expand All @@ -157,7 +158,8 @@ func (c *Client) ImageHistory(name string) ([]ImageHistory, error) {
func (c *Client) RemoveImage(name string) error {
resp, err := c.do(http.MethodDelete, "/images/"+name, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return ErrNoSuchImage
}
return err
Expand All @@ -184,7 +186,8 @@ func (c *Client) RemoveImageExtended(name string, opts RemoveImageOptions) error
uri := fmt.Sprintf("/images/%s?%s", name, queryString(&opts))
resp, err := c.do(http.MethodDelete, uri, doOptions{context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return ErrNoSuchImage
}
return err
Expand All @@ -199,7 +202,8 @@ func (c *Client) RemoveImageExtended(name string, opts RemoveImageOptions) error
func (c *Client) InspectImage(name string) (*Image, error) {
resp, err := c.do(http.MethodGet, "/images/"+name+"/json", doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
return nil, err
Expand Down
Loading

0 comments on commit db93d07

Please sign in to comment.