Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 66.67% |
Changes | 0 |
1 | package validation |
||
2 | |||
3 | import ( |
||
4 | "errors" |
||
5 | "fmt" |
||
6 | "reflect" |
||
7 | ) |
||
8 | |||
9 | // InapplicableConstraintError occurs when trying to use constraint on not applicable values. |
||
10 | // For example, if you are trying to compare slice with a number. |
||
11 | type InapplicableConstraintError struct { |
||
12 | Constraint Constraint |
||
13 | ValueType string |
||
14 | } |
||
15 | |||
16 | func (err InapplicableConstraintError) Error() string { |
||
17 | return fmt.Sprintf("%s cannot be applied to %s", err.Constraint.Name(), err.ValueType) |
||
18 | } |
||
19 | |||
20 | // NewInapplicableConstraintError helps to create a error on trying to use constraint on not applicable values. |
||
21 | func NewInapplicableConstraintError(constraint Constraint, valueType string) InapplicableConstraintError { |
||
22 | 1 | return InapplicableConstraintError{ |
|
23 | Constraint: constraint, |
||
24 | ValueType: valueType, |
||
25 | } |
||
26 | } |
||
27 | |||
28 | // NotValidatableError occurs when validator cannot determine type by reflection or it is not supported |
||
29 | // by validator. |
||
30 | type NotValidatableError struct { |
||
31 | Value reflect.Value |
||
32 | } |
||
33 | |||
34 | func (err NotValidatableError) Error() string { |
||
35 | 1 | return fmt.Sprintf("value of type %v is not validatable", err.Value.Kind()) |
|
36 | } |
||
37 | |||
38 | var errDefaultLanguageNotLoaded = errors.New("default language is not loaded") |
||
39 |