errors: use errdefs errors in client and commands
This change moves from specific, global errors to the errdefs errors. This makes it easy to handle certain classes of errors while still adding context to the failure. Signed-off-by: Stephen Day <stephen.day@getcruise.com>
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
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 command
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnknownLevel is returned when an unknown debugging level is encountered
|
||||
ErrUnknownLevel = errors.New("unknown level")
|
||||
// ErrRegisterAndUnregisterService is returned when both register and unregister flags are specified
|
||||
ErrRegisterAndUnregisterService = errors.New("--register-service and --unregister-service cannot be used together")
|
||||
// ErrEmptyTopic is returned when no topic is provided
|
||||
ErrEmptyTopic = errors.New("topic required to publish event")
|
||||
// ErrEmptyGRCPAddress is returned when the grpc address is empty
|
||||
ErrEmptyGRCPAddress = errors.New("grpc address cannot be empty")
|
||||
)
|
||||
@@ -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 ErrEmptyGRCPAddress
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "grpc address cannot be empty")
|
||||
}
|
||||
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 ErrEmptyTopic
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "topic required to publish event")
|
||||
}
|
||||
payload, err := getEventPayload(os.Stdin)
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,9 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/services/server"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/sys/windows"
|
||||
@@ -161,7 +163,7 @@ func (h *etwHook) Fire(e *logrus.Entry) error {
|
||||
etype = windows.EVENTLOG_INFORMATION_TYPE
|
||||
eid = eventDebug
|
||||
default:
|
||||
return ErrUnknownLevel
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "unknown level")
|
||||
}
|
||||
|
||||
// If there is additional data, include it as a second string.
|
||||
@@ -310,7 +312,7 @@ func registerUnregisterService(root string) (bool, error) {
|
||||
|
||||
if unregisterServiceFlag {
|
||||
if registerServiceFlag {
|
||||
return true, ErrRegisterAndUnregisterService
|
||||
return true, errors.Wrap(errdefs.ErrInvalidArgument, "--register-service and --unregister-service cannot be used together")
|
||||
}
|
||||
return true, unregisterService()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user