From af86cd4d2f45afb156daf93301b2b5dc922cd1cb Mon Sep 17 00:00:00 2001 From: fate-grand-order Date: Fri, 10 Feb 2017 12:32:11 +0800 Subject: [PATCH] Use error.New () directly to output the error message Signed-off-by: fate-grand-order --- cmd/containerd/main.go | 4 ++-- cmd/ctr/delete.go | 4 ++-- cmd/ctr/inspect.go | 4 ++-- cmd/ctr/list.go | 2 +- cmd/ctr/shim.go | 3 ++- cmd/dist/active.go | 2 +- cmd/dist/fetch.go | 4 ++-- testutil/helpers.go | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index 4f71de6..8adb164 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -110,7 +110,7 @@ func main() { debugPath := context.GlobalString("debug-socket") if debugPath == "" { - return fmt.Errorf("--debug-socket path cannot be empty") + return errors.New("--debug-socket path cannot be empty") } d, err := utils.CreateUnixSocket(debugPath) if err != nil { @@ -125,7 +125,7 @@ func main() { path := context.GlobalString("socket") if path == "" { - return fmt.Errorf("--socket path cannot be empty") + return errors.New("--socket path cannot be empty") } l, err := utils.CreateUnixSocket(path) if err != nil { diff --git a/cmd/ctr/delete.go b/cmd/ctr/delete.go index fb4125d..9dfdcba 100644 --- a/cmd/ctr/delete.go +++ b/cmd/ctr/delete.go @@ -2,7 +2,7 @@ package main import ( gocontext "context" - "fmt" + "errors" "github.com/docker/containerd/api/execution" "github.com/urfave/cli" @@ -26,7 +26,7 @@ var deleteCommand = cli.Command{ id := context.Args().First() if id == "" { - return fmt.Errorf("container id must be provided") + return errors.New("container id must be provided") } pid := uint32(context.Int64("pid")) diff --git a/cmd/ctr/inspect.go b/cmd/ctr/inspect.go index b483c68..aa75f19 100644 --- a/cmd/ctr/inspect.go +++ b/cmd/ctr/inspect.go @@ -2,7 +2,7 @@ package main import ( gocontext "context" - "fmt" + "errors" "github.com/davecgh/go-spew/spew" "github.com/docker/containerd/api/execution" @@ -20,7 +20,7 @@ var inspectCommand = cli.Command{ } id := context.Args().First() if id == "" { - return fmt.Errorf("container id must be provided") + return errors.New("container id must be provided") } getResponse, err := executionService.GetContainer(gocontext.Background(), &execution.GetContainerRequest{ID: id}) diff --git a/cmd/ctr/list.go b/cmd/ctr/list.go index 3802bf2..ae40e8f 100644 --- a/cmd/ctr/list.go +++ b/cmd/ctr/list.go @@ -22,7 +22,7 @@ var listCommand = cli.Command{ if err != nil { return err } - fmt.Printf("ID\tSTATUS\tPROCS\tBUNDLE\n") + fmt.Println("ID\tSTATUS\tPROCS\tBUNDLE") for _, c := range listResponse.Containers { listProcResponse, err := executionService.ListProcesses(gocontext.Background(), &execution.ListProcessesRequest{ContainerID: c.ID}) diff --git a/cmd/ctr/shim.go b/cmd/ctr/shim.go index ac4441b..8395aeb 100644 --- a/cmd/ctr/shim.go +++ b/cmd/ctr/shim.go @@ -20,6 +20,7 @@ import ( "github.com/crosbymichael/console" "github.com/docker/containerd/api/shim" "github.com/urfave/cli" + "github.com/pkg/errors" ) var fifoFlags = []cli.Flag{ @@ -75,7 +76,7 @@ var shimCreateCommand = cli.Command{ Action: func(context *cli.Context) error { id := context.Args().First() if id == "" { - return fmt.Errorf("container id must be provided") + return errors.New("container id must be provided") } service, err := getShimService() if err != nil { diff --git a/cmd/dist/active.go b/cmd/dist/active.go index 596f1b4..12be2d3 100644 --- a/cmd/dist/active.go +++ b/cmd/dist/active.go @@ -54,7 +54,7 @@ var activeCommand = cli.Command{ } tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) - fmt.Fprintf(tw, "REF\tSIZE\tAGE\n") + fmt.Fprintln(tw, "REF\tSIZE\tAGE") for _, active := range active { fmt.Fprintf(tw, "%s\t%s\t%s\n", active.Ref, diff --git a/cmd/dist/fetch.go b/cmd/dist/fetch.go index bfab3cd..6af629f 100644 --- a/cmd/dist/fetch.go +++ b/cmd/dist/fetch.go @@ -52,11 +52,11 @@ var fetchCommand = cli.Command{ } if locator == "" { - return fmt.Errorf("containerd: remote required") + return errors.New("containerd: remote required") } if len(args) < 1 { - return fmt.Errorf("containerd: object required") + return errors.New("containerd: object required") } object := args[0] diff --git a/testutil/helpers.go b/testutil/helpers.go index 9e18afb..af46b4b 100644 --- a/testutil/helpers.go +++ b/testutil/helpers.go @@ -60,7 +60,7 @@ func DumpDir(t *testing.T, root string) { } else if fi.Mode().IsRegular() { p, err := ioutil.ReadFile(path) if err != nil { - t.Log("error reading file: %v", err) + t.Logf("error reading file: %v", err) return nil }