Passed
Pull Request — main (#23)
by Igor
01:59
created

validation.*InapplicableConstraintError.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
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
nop 0
1
package validation
2
3
import (
4
	"errors"
5
	"fmt"
6
	"reflect"
7
)
8
9
// InapplicableConstraintError occurs when trying to use constraint on not applicable values.
10
// For example, if you are trying to compare slice with a number.
11
type InapplicableConstraintError struct {
12
	Constraint Constraint
13
	ValueType  string
14
}
15
16
func (err *InapplicableConstraintError) Error() string {
17
	return fmt.Sprintf("%s cannot be applied to %s", err.Constraint.Name(), err.ValueType)
18
}
19
20
func newInapplicableConstraintError(constraint Constraint, valueType string) *InapplicableConstraintError {
21 1
	return &InapplicableConstraintError{
22
		Constraint: constraint,
23
		ValueType:  valueType,
24
	}
25
}
26
27
// NotValidatableError occurs when validator cannot determine type by reflection or it is not supported
28
// by validator.
29
type NotValidatableError struct {
30
	Value reflect.Value
31
}
32
33
func (err *NotValidatableError) Error() string {
34 1
	return fmt.Sprintf("value of type %v is not validatable", err.Value.Kind())
35
}
36
37
var errDefaultLanguageNotLoaded = errors.New("default language is not loaded")
38