Passed
Push — main ( 36e3e5...da04d5 )
by Rushan
01:11 queued 10s
created

validation.*NotValidatableError.Error   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
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
// NewInapplicableConstraintError helps to create a error on trying to use constraint on not applicable values.
21
func NewInapplicableConstraintError(constraint Constraint, valueType string) InapplicableConstraintError {
22 1
	return InapplicableConstraintError{
23
		Constraint: constraint,
24
		ValueType:  valueType,
25
	}
26
}
27
28
// NotValidatableError occurs when validator cannot determine type by reflection or it is not supported
29
// by validator.
30
type NotValidatableError struct {
31
	Value reflect.Value
32
}
33
34
func (err NotValidatableError) Error() string {
35 1
	return fmt.Sprintf("value of type %v is not validatable", err.Value.Kind())
36
}
37
38
var errDefaultLanguageNotLoaded = errors.New("default language is not loaded")
39