Test Failed
Push — main ( faec64...2d1ab0 )
by Igor
01:52
created

validation.*ConstraintNotFoundError.Error   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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