Test Failed
Pull Request — main (#71)
by Igor
02:01
created

validation.ConstraintError.Error   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2.5

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
ccs 1
cts 2
cp 0.5
crap 2.5
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