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