mirror of
https://github.com/valitydev/jesse.git
synced 2024-11-06 09:35:23 +00:00
Revert "breaking: semantics for allowed_errors were off by 1"
This reverts commit 5487c5414d
.
This commit is contained in:
parent
34bcfa526f
commit
47dbcbf41f
@ -164,13 +164,13 @@ works as expected, but let's change the value of the field "c" as well
|
||||
|
||||
still works as expected, jesse stops validating as soon as finds an error.
|
||||
|
||||
Let's use the `allowed_errors` option, and set it to 2
|
||||
Let's use the `allowed_errors` option, and set it to 1
|
||||
|
||||
```erlang
|
||||
5> jesse:validate_with_schema(Schema,
|
||||
5> <<"{\"a\": 1, \"b\": 2, \"c\": 3}">>,
|
||||
5> [{parser_fun, fun jiffy:decode/1},
|
||||
5> {allowed_errors, 2}]).
|
||||
5> {allowed_errors, 1}]).
|
||||
{error,[{data_invalid,{[{<<"type">>,<<"boolean">>}]},
|
||||
wrong_type,3,
|
||||
[<<"c">>]},
|
||||
@ -187,7 +187,7 @@ Let's now change the value of the field "a" to a boolean
|
||||
6> jesse:validate_with_schema(Schema,
|
||||
6> <<"{\"a\": true, \"b\": 2, \"c\": 3}">>,
|
||||
6> [{parser_fun, fun jiffy:decode/1},
|
||||
6> {allowed_errors, 2}]).
|
||||
6> {allowed_errors, 1}]).
|
||||
{error,[{data_invalid,{[{<<"type">>,<<"string">>}]},
|
||||
wrong_type,2,
|
||||
[<<"b">>]},
|
||||
|
@ -62,11 +62,10 @@
|
||||
, ErrorList :: [error_reason()]
|
||||
, AllowedErrors :: jesse_state:allowed_errors()
|
||||
) -> [error_reason()] | no_return().
|
||||
default_error_handler(Error, ErrorList0, AllowedErrors) ->
|
||||
ErrorList = ErrorList0 ++ [Error],
|
||||
default_error_handler(Error, ErrorList, AllowedErrors) ->
|
||||
case AllowedErrors > length(ErrorList) orelse AllowedErrors =:= ?infinity of
|
||||
true -> ErrorList;
|
||||
false -> throw(ErrorList)
|
||||
true -> ErrorList ++ [Error];
|
||||
false -> throw(ErrorList ++ [Error])
|
||||
end.
|
||||
|
||||
%% @doc Generates a new data error and returns the updated state.
|
||||
|
Loading…
Reference in New Issue
Block a user