-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathErrorMessages.elm
113 lines (81 loc) · 3.41 KB
/
ErrorMessages.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
module ErrorMessages exposing (stringifyError)
import Json.Encode as Encode
import Json.Schema.Validation as Validation exposing (ValidationError(..))
pluralize : Int -> String -> String
pluralize n name =
case n of
1 ->
"1 " ++ name
_ ->
String.fromInt n ++ " " ++ name ++ "s"
stringifyError : Validation.ValidationError -> String
stringifyError e =
case e of
MultipleOf multiplier actual ->
String.fromFloat actual
++ " is not a multiple of "
++ String.fromFloat multiplier
Maximum max actual ->
String.fromFloat actual ++ " is more than maximum " ++ String.fromFloat max
Minimum min actual ->
String.fromFloat actual ++ " is less than minimum " ++ String.fromFloat min
ExclusiveMaximum max actual ->
String.fromFloat actual ++ " is not less than exclusive maximum " ++ String.fromFloat max
ExclusiveMinimum min actual ->
String.fromFloat actual ++ " is not more than exclusive minimum " ++ String.fromFloat min
MaxLength expected actual ->
"Longer than "
++ pluralize expected "character"
MinLength expected actual ->
"Shorter than "
++ pluralize expected "character"
Pattern pattern string ->
"Does not match pattern " ++ pattern
MaxItems expected actual ->
"List expected to have at most "
++ pluralize expected "item"
++ " but it has "
++ pluralize actual "item"
MinItems expected actual ->
"List expected to have at least "
++ pluralize expected "item"
++ " but it has "
++ pluralize actual "item"
UniqueItems x ->
"Expected array of unique items, but a duplicate found: " ++ Encode.encode 0 x
Contains ->
"None of array items is valid against the given schema"
MaxProperties expected actual ->
"MaxProperties"
MinProperties expected actual ->
"MinProperties"
RequiredProperty ->
"This property is required"
Required missingPropertyNames ->
""
AdditionalPropertyDisallowed ->
"This is an additional property and it is not allowed"
AdditionalPropertiesDisallowed extraPropertyNames ->
""
{-
"Additional properties are not allowed here, but I see "
++ (extraPropertyNames |> List.map toString |> String.join ", ")
-}
InvalidPropertyName invalidPropertyNames ->
"Some property names are not passing validation"
Enum ->
"Value does not match enumeration defined in the schema"
Const ->
"Value does not match const defined in the schema"
InvalidType s ->
s
OneOfNoneSucceed ->
"Value does not pass the validation with none of the schemata listed in '.oneOf'"
OneOfManySucceed int ->
"Value should pass validation with exactly one schema, but " ++ String.fromInt int ++ " return a positive result"
Not ->
"This value expected to fail validation"
AlwaysFail ->
"This is not expected to succeed"
UnresolvableReference ref ->
"Reference " ++ ref ++ " can not be resolved"