func All(err error) []error {
	if ec, ok := err.(*errorCollection); ok {
		all := make([]error, len(ec.errs))
		copy(all, ec.errs)
		return all
	}
	return []error{err}
}
All returns a slice of errors in case of collected errors.
package errors
import (
	"fmt"
	"path"
	"runtime"
	"strings"
)
type Messages map[int]string
func (m Messages) Format(code int, args ...interface{}) string {
	if m == nil || m[code] == "" {
		if len(args) == 0 {
			return fmt.Sprintf("[ERRORS:999] invalid error code '%d'", code)
		}
		format := fmt.Sprintf("%v", args[0])
		return fmt.Sprintf(format, args[1:]...)
	}
	format := m[code]
	return fmt.Sprintf(format, args...)
}
const (
	ErrInvalidErrorType = iota + 1
	ErrNotYetImplemented
	ErrDeprecated
)
var errorMessages = Messages{
	ErrInvalidErrorType:  "invalid error type: %T %q",
	ErrNotYetImplemented: "feature is not yet implemented: %q",
	ErrDeprecated:        "feature is deprecated: %q",
}
type errorBox struct {
	err  error
	code int
	msg  string
	info *callInfo
}
func newErrorBox(err error, code int, msgs Messages, args ...interface{}) *errorBox {
	return &errorBox{
		err:  err,
		code: code,
		msg:  msgs.Format(code, args...),
		info: retrieveCallInfo(),
	}
}
func (eb *errorBox) Error() string {
	if eb.err != nil {
		return fmt.Sprintf("[%s:%03d] %s: %v", eb.info.packagePart, eb.code, eb.msg, eb.err)
	}
	return fmt.Sprintf("[%s:%03d] %s", eb.info.packagePart, eb.code, eb.msg)
}
type errorCollection struct {
	errs []error
}
func (ec *errorCollection) Error() string {
	errMsgs := make([]string, len(ec.errs))
	for i, err := range ec.errs {
		errMsgs[i] = err.Error()
	}
	return strings.Join(errMsgs, "\n")
}
func Annotate(err error, code int, msgs Messages, args ...interface{}) error {
	return newErrorBox(err, code, msgs, args...)
}
func New(code int, msgs Messages, args ...interface{}) error {
	return newErrorBox(nil, code, msgs, args...)
}
func Collect(errs ...error) error {
	return &errorCollection{
		errs: errs,
	}
}
func Valid(err error) bool {
	_, ok := err.(*errorBox)
	return ok
}
func IsError(err error, code int) bool {
	if e, ok := err.(*errorBox); ok {
		return e.code == code
	}
	return false
}
func Annotated(err error) error {
	if e, ok := err.(*errorBox); ok {
		return e.err
	}
	return New(ErrInvalidErrorType, errorMessages, err, err)
}
func Location(err error) (string, string, int, error) {
	if e, ok := err.(*errorBox); ok {
		return e.info.packageName, e.info.fileName, e.info.line, nil
	}
	return "", "", 0, New(ErrInvalidErrorType, errorMessages, err, err)
}
func Stack(err error) []error {
	if eb, ok := err.(*errorBox); ok {
		return append([]error{eb}, Stack(eb.err)...)
	}
	return []error{err}
}