You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
906 B

4 years ago
package input
import (
"errors"
"fmt"
)
var (
ErrNotFound = errors.New("not found")
ErrNoArgs = errors.New("no arguments expected")
ErrToManyArgs = errors.New("too many arguments")
ErrUnexpectedType = errors.New("unexpected type")
ErrRequired = errors.New("is required")
ErrAppend = errors.New("failed append")
ErrInvalidName = errors.New("invalid name")
)
type Error struct {
name string
err error
t string
}
func (o Error) Error() string {
return fmt.Sprintf("%s: '%s' %s", o.t, o.name, o.err)
}
func (o Error) Is(err error) bool {
return errors.Is(err, o.err)
}
func (o Error) Unwrap() error {
return o.err
}
func ErrorOption(name string, err error) Error {
return Error{
name: name,
err: err,
t: "option",
}
}
func ErrorArgument(name string, err error) Error {
return Error{
name: name,
err: err,
t: "argument",
}
}