Improve error message for WithContainerExtension
The previous error messages are not very descriptive in how to fix the issue, especially since they come from container create and not when calling `WithContainerExtensions`. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
c66fd83eae
commit
0847ae6cdf
@ -150,18 +150,21 @@ func setSnapshotterIfEmpty(c *containers.Container) {
|
||||
// integration.
|
||||
//
|
||||
// Make sure to register the type of `extension` in the typeurl package via
|
||||
// `typeurl.Register` otherwise the type data will be inferred, including how
|
||||
// to encode and decode the object.
|
||||
// `typeurl.Register` or container creation may fail.
|
||||
func WithContainerExtension(name string, extension interface{}) NewContainerOpts {
|
||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||
any, err := typeurl.MarshalAny(extension)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "extension key must not be zero-length")
|
||||
}
|
||||
|
||||
any, err := typeurl.MarshalAny(extension)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == typeurl.ErrNotFound {
|
||||
return errors.Wrapf(err, "extension %q is not registered with the typeurl package, see `typeurl.Register`", name)
|
||||
}
|
||||
return errors.Wrap(err, "error marshalling extension")
|
||||
}
|
||||
|
||||
if c.Extensions == nil {
|
||||
c.Extensions = make(map[string]types.Any)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user