Merge pull request #1644 from cpuguy83/unmarshal_error_desc
Improve error message for `WithContainerExtension`
This commit is contained in:
commit
103dd0e75e
@ -150,18 +150,21 @@ func setSnapshotterIfEmpty(c *containers.Container) {
|
|||||||
// integration.
|
// integration.
|
||||||
//
|
//
|
||||||
// Make sure to register the type of `extension` in the typeurl package via
|
// Make sure to register the type of `extension` in the typeurl package via
|
||||||
// `typeurl.Register` otherwise the type data will be inferred, including how
|
// `typeurl.Register` or container creation may fail.
|
||||||
// to encode and decode the object.
|
|
||||||
func WithContainerExtension(name string, extension interface{}) NewContainerOpts {
|
func WithContainerExtension(name string, extension interface{}) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
any, err := typeurl.MarshalAny(extension)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "extension key must not be zero-length")
|
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 {
|
if c.Extensions == nil {
|
||||||
c.Extensions = make(map[string]types.Any)
|
c.Extensions = make(map[string]types.Any)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user