Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 75% |
Changes | 0 |
1 | package validation |
||
2 | |||
3 | import ( |
||
4 | "errors" |
||
5 | "fmt" |
||
6 | "strings" |
||
7 | ) |
||
8 | |||
9 | // ConstraintError is used to return critical error from constraint that immediately |
||
10 | // stops the validation process. It is recommended to use Scope.NewConstraintError() method |
||
11 | // to initiate an error from current scope. |
||
12 | type ConstraintError struct { |
||
13 | ConstraintName string |
||
14 | Path *PropertyPath |
||
15 | Description string |
||
16 | } |
||
17 | |||
18 | func (err *ConstraintError) Error() string { |
||
19 | var s strings.Builder |
||
20 | s.WriteString("failed to validate by " + err.ConstraintName) |
||
21 | if err.Path != nil { |
||
22 | 1 | s.WriteString(` at path "` + err.Path.String() + `"`) |
|
23 | } |
||
24 | s.WriteString(": " + err.Description) |
||
25 | |||
26 | return s.String() |
||
27 | } |
||
28 | |||
29 | // ConstraintAlreadyStoredError is returned when trying to put a constraint |
||
30 | // in the validator store using an existing key. |
||
31 | type ConstraintAlreadyStoredError struct { |
||
32 | Key string |
||
33 | } |
||
34 | |||
35 | 1 | func (err *ConstraintAlreadyStoredError) Error() string { |
|
36 | return fmt.Sprintf(`constraint with key "%s" already stored`, err.Key) |
||
37 | } |
||
38 | |||
39 | // ConstraintNotFoundError is returned when trying to get a constraint |
||
40 | // from the validator store using a non-existent key. |
||
41 | type ConstraintNotFoundError struct { |
||
42 | Key string |
||
43 | Type string |
||
44 | } |
||
45 | 1 | ||
46 | func (err *ConstraintNotFoundError) Error() string { |
||
47 | return fmt.Sprintf(`constraint by key "%s" of type "%s" is not found`, err.Key, err.Type) |
||
48 | } |
||
49 | |||
50 | var errTranslatorOptionsDenied = errors.New("translation options denied when using custom translator") |
||
51 |