func (errs Errors) MarshalJSON() ([]byte, error) {
	var tmpErrs struct {
		Errors []Error `json:"errors,omitempty"`
	}
	for _, daErr := range errs {
		var err Error
		switch daErr := daErr.(type) {
		case ErrorCode:
			err = daErr.WithDetail(nil)
		case Error:
			err = daErr
		default:
			err = ErrorCodeUnknown.WithDetail(daErr)
		}
		msg := err.Message
		if msg == "" {
			msg = err.Code.Message()
		}
		tmpErrs.Errors = append(tmpErrs.Errors, Error{
			Code:    err.Code,
			Message: msg,
			Detail:  err.Detail,
		})
	}
	return json.Marshal(tmpErrs)
}
MarshalJSON converts slice of error, ErrorCode or Error into a
slice of Error - then serializes
package docker
import (
	"encoding/json"
	"fmt"
	"strings"
)
type ErrorCoder interface {
	ErrorCode() ErrorCode
}
type ErrorCode int
var _ error = ErrorCode(0)
func (ec ErrorCode) ErrorCode() ErrorCode {
	return ec
}
func (ec ErrorCode) Error() string {
	return strings.ToLower(strings.Replace(ec.String(), "_", " ", -1))
}
func (ec ErrorCode) Descriptor() ErrorDescriptor {
	d, ok := errorCodeToDescriptors[ec]
	if !ok {
		return ErrorCodeUnknown.Descriptor()
	}
	return d
}
func (ec ErrorCode) String() string {
	return ec.Descriptor().Value
}
func (ec ErrorCode) Message() string {
	return ec.Descriptor().Message
}
func (ec ErrorCode) MarshalText() (text []byte, err error) {
	return []byte(ec.String()), nil
}
func (ec *ErrorCode) UnmarshalText(text []byte) error {
	desc, ok := idToDescriptors[string(text)]
	if !ok {
		desc = ErrorCodeUnknown.Descriptor()
	}
	*ec = desc.Code
	return nil
}
func (ec ErrorCode) WithMessage(message string) Error {
	return Error{
		Code:    ec,
		Message: message,
	}
}
func (ec ErrorCode) WithDetail(detail interface{}) Error {
	return Error{
		Code:    ec,
		Message: ec.Message(),
	}.WithDetail(detail)
}
func (ec ErrorCode) WithArgs(args ...interface{}) Error {
	return Error{
		Code:    ec,
		Message: ec.Message(),
	}.WithArgs(args...)
}
type Error struct {
	Code    ErrorCode   `json:"code"`
	Message string      `json:"message"`
	Detail  interface{} `json:"detail,omitempty"`
}
var _ error = Error{}
func (e Error) ErrorCode() ErrorCode {
	return e.Code
}
func (e Error) Error() string {
	return fmt.Sprintf("%s: %s", e.Code.Error(), e.Message)
}
func (e Error) WithDetail(detail interface{}) Error {
	return Error{
		Code:    e.Code,
		Message: e.Message,
		Detail:  detail,
	}
}
func (e Error) WithArgs(args ...interface{}) Error {
	return Error{
		Code:    e.Code,
		Message: fmt.Sprintf(e.Code.Message(), args...),
		Detail:  e.Detail,
	}
}
type ErrorDescriptor struct {
	Code ErrorCode
	Value string
	Message string
	Description string
	HTTPStatusCode int
}
func ParseErrorCode(value string) ErrorCode {
	ed, ok := idToDescriptors[value]
	if ok {
		return ed.Code
	}
	return ErrorCodeUnknown
}
type Errors []error
var _ error = Errors{}
func (errs Errors) Error() string {
	switch len(errs) {
	case 0:
		return "<nil>"
	case 1:
		return errs[0].Error()
	default:
		msg := "errors:\n"
		for _, err := range errs {
			msg += err.Error() + "\n"
		}
		return msg
	}
}
func (errs Errors) Len() int {
	return len(errs)
}