1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #11402 from miminar/err-cleanup

Error formatting cleanups
This commit is contained in:
Michael Crosby 2015-03-16 16:13:16 -07:00
commit 88f437d6c6
14 changed files with 24 additions and 24 deletions

View file

@ -920,7 +920,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
obj, _, err := readBody(cli.call("GET", "/containers/"+name+"/json", nil, false))
if err != nil {
if strings.Contains(err.Error(), "Too many") {
fmt.Fprintf(cli.err, "Error: %s", err.Error())
fmt.Fprintf(cli.err, "Error: %v", err)
status = 1
continue
}
@ -2795,7 +2795,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
for _, c := range cStats {
c.mu.Lock()
if c.err != nil {
errs = append(errs, fmt.Sprintf("%s: %s", c.Name, c.err.Error()))
errs = append(errs, fmt.Sprintf("%s: %v", c.Name, c.err))
}
c.mu.Unlock()
}

View file

@ -104,7 +104,7 @@ func FormGroup(key string, start, last int) string {
func MatchesContentType(contentType, expectedType string) bool {
mimetype, _, err := mime.ParseMediaType(contentType)
if err != nil {
log.Errorf("Error parsing media type: %s error: %s", contentType, err.Error())
log.Errorf("Error parsing media type: %s error: %v", contentType, err)
}
return err == nil && mimetype == expectedType
}

View file

@ -134,7 +134,7 @@ func httpError(w http.ResponseWriter, err error) {
}
if err != nil {
log.Errorf("HTTP Error: statusCode=%d %s", statusCode, err.Error())
log.Errorf("HTTP Error: statusCode=%d %v", statusCode, err)
http.Error(w, err.Error(), statusCode)
}
}
@ -1122,7 +1122,7 @@ func postContainersCopy(eng *engine.Engine, version version.Version, w http.Resp
job.Stdout.Add(w)
w.Header().Set("Content-Type", "application/x-tar")
if err := job.Run(); err != nil {
log.Errorf("%s", err.Error())
log.Errorf("%v", err)
if strings.Contains(strings.ToLower(err.Error()), "no such id") {
w.WriteHeader(http.StatusNotFound)
} else if strings.Contains(err.Error(), "no such file or directory") {

View file

@ -734,7 +734,7 @@ func (b *Builder) clearTmp() {
}
if err := b.Daemon.Rm(tmp); err != nil {
fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %s\n", common.TruncateID(c), err.Error())
fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %v\n", common.TruncateID(c), err)
return
}
b.Daemon.DeleteVolumes(tmp.VolumePaths())

View file

@ -33,7 +33,7 @@ func TestTestNegative(t *testing.T) {
df, err := os.Open(dockerfile)
if err != nil {
t.Fatalf("Dockerfile missing for %s: %s", dir, err.Error())
t.Fatalf("Dockerfile missing for %s: %v", dir, err)
}
_, err = Parse(df)
@ -52,18 +52,18 @@ func TestTestData(t *testing.T) {
df, err := os.Open(dockerfile)
if err != nil {
t.Fatalf("Dockerfile missing for %s: %s", dir, err.Error())
t.Fatalf("Dockerfile missing for %s: %v", dir, err)
}
defer df.Close()
ast, err := Parse(df)
if err != nil {
t.Fatalf("Error parsing %s's dockerfile: %s", dir, err.Error())
t.Fatalf("Error parsing %s's dockerfile: %v", dir, err)
}
content, err := ioutil.ReadFile(resultfile)
if err != nil {
t.Fatalf("Error reading %s's result file: %s", dir, err.Error())
t.Fatalf("Error reading %s's result file: %v", dir, err)
}
if ast.Dump()+"\n" != string(content) {

View file

@ -1015,10 +1015,10 @@ func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error)
log.Errorf("portallocator.ReleaseAll(): %s", err)
}
if err := daemon.driver.Cleanup(); err != nil {
log.Errorf("daemon.driver.Cleanup(): %s", err.Error())
log.Errorf("daemon.driver.Cleanup(): %v", err)
}
if err := daemon.containerGraph.Close(); err != nil {
log.Errorf("daemon.containerGraph.Close(): %s", err.Error())
log.Errorf("daemon.containerGraph.Close(): %v", err)
}
})

View file

@ -73,7 +73,7 @@ func newDriver(t *testing.T, name string) *Driver {
d, err := graphdriver.GetDriver(name, root, nil)
if err != nil {
t.Logf("graphdriver: %s\n", err.Error())
t.Logf("graphdriver: %v\n", err)
if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites || err == graphdriver.ErrIncompatibleFS {
t.Skipf("Driver %s not supported", name)
}

View file

@ -531,7 +531,7 @@ func Allocate(job *engine.Job) engine.Status {
globalIPv6, err = ipallocator.RequestIP(globalIPv6Network, requestedIPv6)
if err != nil {
log.Errorf("Allocator: RequestIP v6: %s", err.Error())
log.Errorf("Allocator: RequestIP v6: %v", err)
return job.Error(err)
}
log.Infof("Allocated IPv6 %s", globalIPv6)

View file

@ -69,11 +69,11 @@ func NewErrPortAlreadyAllocated(ip string, port int) ErrPortAlreadyAllocated {
}
func init() {
const param = "/proc/sys/net/ipv4/ip_local_port_range"
const portRangeKernelParam = "/proc/sys/net/ipv4/ip_local_port_range"
file, err := os.Open(param)
file, err := os.Open(portRangeKernelParam)
if err != nil {
log.Errorf("Failed to read %s kernel parameter: %s", param, err.Error())
log.Errorf("Failed to read %s kernel parameter: %v", portRangeKernelParam, err)
return
}
var start, end int
@ -82,7 +82,7 @@ func init() {
if err == nil {
err = fmt.Errorf("unexpected count of parsed numbers (%d)", n)
}
log.Errorf("Failed to parse port range from %s: %v", param, err)
log.Errorf("Failed to parse port range from %s: %v", portRangeKernelParam, err)
return
}
beginPortRange = start

View file

@ -66,7 +66,7 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.
if err != nil && os.IsNotExist(err) {
err = os.MkdirAll(source, 0755)
if err != nil {
return fmt.Errorf("Could not create local directory '%s' for bind mount: %s!", source, err.Error())
return fmt.Errorf("Could not create local directory '%s' for bind mount: %v!", source, err)
}
}
}

View file

@ -13,7 +13,7 @@ func (daemon *Daemon) ContainerWait(job *engine.Job) engine.Status {
name := job.Args[0]
container, err := daemon.Get(name)
if err != nil {
return job.Errorf("%s: %s", job.Name, err.Error())
return job.Errorf("%s: %v", job.Name, err)
}
status, _ := container.WaitStop(-1 * time.Second)
job.Printf("%d\n", status)

View file

@ -307,7 +307,7 @@ func TestDaemonCreate(t *testing.T) {
"conflictname",
)
if _, _, err := daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID, Cmd: []string{"ls", "-al"}}, &runconfig.HostConfig{}, testContainer.Name); err == nil || !strings.Contains(err.Error(), common.TruncateID(testContainer.ID)) {
t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %s", err.Error())
t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %v", err)
}
// Make sure create with bad parameters returns an error

View file

@ -30,7 +30,7 @@ func Listeners(unsetEnv bool) ([]net.Listener, error) {
var err error
listeners[i], err = net.FileListener(f)
if err != nil {
return nil, fmt.Errorf("Error setting up FileListener for fd %d: %s", f.Fd(), err.Error())
return nil, fmt.Errorf("Error setting up FileListener for fd %d: %v", f.Fd(), err)
}
}

View file

@ -198,7 +198,7 @@ this is just some garbage data
execUser, err := GetExecUser(test.ref, &defaultExecUser, passwd, group)
if err != nil {
t.Logf("got unexpected error when parsing '%s': %s", test.ref, err.Error())
t.Logf("got unexpected error when parsing '%s': %v", test.ref, err)
t.Fail()
continue
}
@ -337,7 +337,7 @@ this is just some garbage data
execUser, err := GetExecUser(test.ref, &defaultExecUser, passwd, group)
if err != nil {
t.Logf("got unexpected error when parsing '%s': %s", test.ref, err.Error())
t.Logf("got unexpected error when parsing '%s': %v", test.ref, err)
t.Fail()
continue
}