github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/cli-plugins/manager/error.go (about)

     1  package manager
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  )
     6  
     7  // pluginError is set as Plugin.Err by NewPlugin if the plugin
     8  // candidate fails one of the candidate tests. This exists primarily
     9  // to implement encoding.TextMarshaller such that rendering a plugin as JSON
    10  // (e.g. for `docker info -f '{{json .CLIPlugins}}'`) renders the Err
    11  // field as a useful string and not just `{}`. See
    12  // https://github.com/golang/go/issues/10748 for some discussion
    13  // around why the builtin error type doesn't implement this.
    14  type pluginError struct {
    15  	cause error
    16  }
    17  
    18  // Error satisfies the core error interface for pluginError.
    19  func (e *pluginError) Error() string {
    20  	return e.cause.Error()
    21  }
    22  
    23  // Cause satisfies the errors.causer interface for pluginError.
    24  func (e *pluginError) Cause() error {
    25  	return e.cause
    26  }
    27  
    28  // Unwrap provides compatibility for Go 1.13 error chains.
    29  func (e *pluginError) Unwrap() error {
    30  	return e.cause
    31  }
    32  
    33  // MarshalText marshalls the pluginError into a textual form.
    34  func (e *pluginError) MarshalText() (text []byte, err error) {
    35  	return []byte(e.cause.Error()), nil
    36  }
    37  
    38  // wrapAsPluginError wraps an error in a pluginError with an
    39  // additional message, analogous to errors.Wrapf.
    40  func wrapAsPluginError(err error, msg string) error {
    41  	return &pluginError{cause: errors.Wrap(err, msg)}
    42  }
    43  
    44  // NewPluginError creates a new pluginError, analogous to
    45  // errors.Errorf.
    46  func NewPluginError(msg string, args ...interface{}) error {
    47  	return &pluginError{cause: errors.Errorf(msg, args...)}
    48  }