errors

package
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorSet

type ErrorSet struct {
	// contains filtered or unexported fields
}
Example
subErrSet := NewErrorSet("")
subErrSet.AddErr(fmt.Errorf("err"), "PropA")
subErrSet.AddErr(fmt.Errorf("err"), "PropB")

errSet := NewErrorSet("")
errSet.AddErr(fmt.Errorf("err"), "Key")
errSet.AddErr(subErrSet.Err(), "Key", 1)
errSet.AddErr(NewErrorSet("").Err(), "Key", 1)

fmt.Println(errSet.Len())
fmt.Println(errSet)
Output:

3
Key err
Key[1].PropA err
Key[1].PropB err

func NewErrorSet

func NewErrorSet(root string) *ErrorSet

func (*ErrorSet) AddErr

func (errorSet *ErrorSet) AddErr(err error, keyPathNodes ...interface{})

func (*ErrorSet) Each

func (errorSet *ErrorSet) Each(cb func(fieldErr *FieldError))

func (*ErrorSet) Err

func (errorSet *ErrorSet) Err() error

func (*ErrorSet) Error

func (errorSet *ErrorSet) Error() string

func (*ErrorSet) Flatten

func (errorSet *ErrorSet) Flatten() *ErrorSet

func (*ErrorSet) Len

func (errorSet *ErrorSet) Len() int

type FieldError

type FieldError struct {
	Field KeyPath
	Error error `json:"msg"`
}

type KeyPath

type KeyPath []interface{}

func (KeyPath) String

func (keyPath KeyPath) String() string

type MissingRequiredFieldError

type MissingRequiredFieldError struct{}
Example
fmt.Println(MissingRequiredFieldError{})
Output:

missing required field

func (MissingRequiredFieldError) Error

type MultipleOfError

type MultipleOfError struct {
	Target     string
	Current    interface{}
	MultipleOf interface{}
}
Example
fmt.Println(&MultipleOfError{
	Target:     "int value",
	Current:    "11",
	MultipleOf: 2,
})
Output:

int value should be multiple of 2, but got invalid value 11

func (*MultipleOfError) Error

func (e *MultipleOfError) Error() string

type NotInEnumError

type NotInEnumError struct {
	Target  string
	Current interface{}
	Enums   []interface{}
}
Example
fmt.Println(&NotInEnumError{
	Target:  "int value",
	Current: "11",
	Enums: []interface{}{
		"1", "2", "3",
	},
})
Output:

int value should be one of 1, 2, 3, but got invalid value 11

func (*NotInEnumError) Error

func (e *NotInEnumError) Error() string

type NotMatchError

type NotMatchError struct {
	Target  string
	Current interface{}
	Pattern *regexp.Regexp
}
Example
fmt.Println(&NotMatchError{
	Target:  "number",
	Current: "1",
	Pattern: regexp.MustCompile(`/\d+/`),
})
Output:

number /\d+/ not match 1

func (*NotMatchError) Error

func (err *NotMatchError) Error() string

type OutOfRangeError

type OutOfRangeError struct {
	Target           string
	Current          interface{}
	Minimum          interface{}
	Maximum          interface{}
	ExclusiveMaximum bool
	ExclusiveMinimum bool
}
Example
fmt.Println(&OutOfRangeError{
	Target:           "int value",
	Minimum:          "1",
	Maximum:          "10",
	Current:          "11",
	ExclusiveMinimum: true,
	ExclusiveMaximum: true,
})
Output:

int value should be larger or equal than 1 and less or equal than 10, but got invalid value 11

func (*OutOfRangeError) Error

func (e *OutOfRangeError) Error() string

type SyntaxError

type SyntaxError struct {
	Msg string
}
Example
fmt.Println(NewSyntaxError("rule"))
Output:

invalid syntax: rule

func NewSyntaxError

func NewSyntaxError(format string, args ...interface{}) *SyntaxError

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type UnsupportedTypeError

type UnsupportedTypeError struct {
	// contains filtered or unexported fields
}
Example
fmt.Println(NewUnsupportedTypeError("string", "@int", "something wrong", "something wrong"))
Output:

@int could not validate type string: something wrong; something wrong

func NewUnsupportedTypeError

func NewUnsupportedTypeError(typ string, rule string, msgs ...string) *UnsupportedTypeError

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL