Revert "breaking: semantics for allowed_errors were off by 1"

This reverts commit 5487c5414d.
This commit is contained in:
Andrei Neculau 2018-02-14 15:49:51 +01:00
parent 34bcfa526f
commit 47dbcbf41f
2 changed files with 6 additions and 7 deletions

View File

@ -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">>]},

View File

@ -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.