centralize harded-code message
Signed-off-by: Fahed Dorgaa <fahed.dorgaa@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/services/server"
|
||||
@@ -152,7 +153,7 @@ func App() *cli.App {
|
||||
ttrpcAddress = fmt.Sprintf("%s.ttrpc", config.GRPC.Address)
|
||||
)
|
||||
if address == "" {
|
||||
return errors.New("grpc address cannot be empty")
|
||||
return errdefs.ErrEmptyGRCPAddress
|
||||
}
|
||||
log.G(ctx).WithFields(logrus.Fields{
|
||||
"version": version.Version,
|
||||
|
||||
@@ -51,7 +51,7 @@ var publishCommand = cli.Command{
|
||||
ctx := namespaces.WithNamespace(gocontext.Background(), context.String("namespace"))
|
||||
topic := context.String("topic")
|
||||
if topic == "" {
|
||||
return errors.New("topic required to publish event")
|
||||
return errdefs.ErrEmptyTopic
|
||||
}
|
||||
payload, err := getEventPayload(os.Stdin)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -28,6 +27,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/services/server"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@@ -162,7 +162,7 @@ func (h *etwHook) Fire(e *logrus.Entry) error {
|
||||
etype = windows.EVENTLOG_INFORMATION_TYPE
|
||||
eid = eventDebug
|
||||
default:
|
||||
return errors.New("unknown level")
|
||||
return errdefs.ErrUnknownLevel
|
||||
}
|
||||
|
||||
// If there is additional data, include it as a second string.
|
||||
@@ -311,7 +311,7 @@ func registerUnregisterService(root string) (bool, error) {
|
||||
|
||||
if unregisterServiceFlag {
|
||||
if registerServiceFlag {
|
||||
return true, errors.New("--register-service and --unregister-service cannot be used together")
|
||||
return true, errdefs.ErrRegisterAndUnregisterService
|
||||
}
|
||||
return true, unregisterService()
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import (
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands/run"
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/typeurl"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -65,17 +65,17 @@ var createCommand = cli.Command{
|
||||
if config {
|
||||
id = context.Args().First()
|
||||
if context.NArg() > 1 {
|
||||
return errors.New("with spec config file, only container id should be provided")
|
||||
return errdefs.ErrArgConfigFile
|
||||
}
|
||||
} else {
|
||||
id = context.Args().Get(1)
|
||||
ref = context.Args().First()
|
||||
if ref == "" {
|
||||
return errors.New("image ref must be provided")
|
||||
return errdefs.ErrUnprovidedImageRef
|
||||
}
|
||||
}
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
return errdefs.ErrEmptyContainerId
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
@@ -168,7 +168,7 @@ var deleteCommand = cli.Command{
|
||||
}
|
||||
|
||||
if context.NArg() == 0 {
|
||||
return errors.New("must specify at least one container to delete")
|
||||
return errdefs.ErrDeleteNoneContainer
|
||||
}
|
||||
for _, arg := range context.Args() {
|
||||
if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil {
|
||||
@@ -214,7 +214,7 @@ var setLabelsCommand = cli.Command{
|
||||
Action: func(context *cli.Context) error {
|
||||
containerID, labels := commands.ObjectWithLabelArgs(context)
|
||||
if containerID == "" {
|
||||
return errors.New("container id must be provided")
|
||||
return errdefs.ErrEmptyContainerId
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
@@ -250,7 +250,7 @@ var infoCommand = cli.Command{
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
return errdefs.ErrEmptyContainerId
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user