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

errors.go   A

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
cc 4
eloc 26
dl 0
loc 47
ccs 3
cts 4
cp 0.75
crap 4.25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validation.ConstraintError.Error 0 9 2
A validation.ConstraintAlreadyStoredError.Error 0 2 1
A validation.ConstraintNotFoundError.Error 0 2 1
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