Merge pull request #3416 from crosbymichael/hard-code-err
Replace hard coded error messages
This commit is contained in:
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/typeurl"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -65,17 +64,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 commands.ErrArgConfigFile
|
||||
}
|
||||
} else {
|
||||
id = context.Args().Get(1)
|
||||
ref = context.Args().First()
|
||||
if ref == "" {
|
||||
return errors.New("image ref must be provided")
|
||||
return commands.ErrUnprovidedImageRef
|
||||
}
|
||||
}
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
return commands.ErrEmptyContainerID
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
@@ -168,7 +167,7 @@ var deleteCommand = cli.Command{
|
||||
}
|
||||
|
||||
if context.NArg() == 0 {
|
||||
return errors.New("must specify at least one container to delete")
|
||||
return commands.ErrDeleteNoneContainer
|
||||
}
|
||||
for _, arg := range context.Args() {
|
||||
if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil {
|
||||
@@ -214,7 +213,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 commands.ErrEmptyContainerID
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
@@ -250,7 +249,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 commands.ErrEmptyContainerID
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
if err != nil {
|
||||
|
||||
32
cmd/ctr/commands/error.go
Normal file
32
cmd/ctr/commands/error.go
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrArgConfigFile is returned when the configuration for a spec is provided
|
||||
ErrArgConfigFile = errors.New("with spec config file, only container id should be provided")
|
||||
// ErrUnprovidedImageRef is returned when no image reference is provided
|
||||
ErrUnprovidedImageRef = errors.New("image ref must be provided")
|
||||
// ErrEmptyContainerID is returned when no container id is provided
|
||||
ErrEmptyContainerID = errors.New("container id must be provided")
|
||||
// ErrDeleteNoneContainer is returned when no container ids are provided for deletion
|
||||
ErrDeleteNoneContainer = errors.New("must specify at least one container to delete")
|
||||
)
|
||||
Reference in New Issue
Block a user