Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

z_apply custom errors #5

Merged
merged 1 commit into from

2 participants

@shizzard

One-line patch.
Allows z_apply to handle custom errors from arg funs, e.g.

a(X) when is_integer(X) -> {ok, X*2};
a(X) when is_atom(X) -> {error, atom_not_allowed};
a(X) when is_list(X) -> {error, lists_not_allowed}.

z_apply(fun a/1, z_wrap(123), {error, generic}), %% result is 246
z_apply(fun a/1, z_wrap(atom), {error, generic}), %% throws {error, atom_not_allowed}
z_apply(fun a/1, z_wrap([a,b,c]), {error, generic}), %% throws {error, lists_not_allowed} 
z_apply(fun a/1, z_wrap({illegal_pattern}), {error, generic}). %% throws {error, generic} because of pattern mismatch
@si14 si14 merged commit 292c85e into si14:master
@si14
Owner

Thanks for contribution! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @shizzard
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  src/z_validate.erl
View
1  src/z_validate.erl
@@ -83,6 +83,7 @@ z_apply(Fun, ?Z_VALUE(_, Err)=ZVal) ->
z_apply(Fun, ?Z_VALUE(Val, _Err), NewErr) ->
case catch Fun(Val) of
{ok, NewVal} -> ?Z_VALUE(NewVal, NewErr);
+ {error, Err} -> ?THROW_Z_ERROR(Err);
_ -> ?THROW_Z_ERROR(NewErr)
end.
Something went wrong with that request. Please try again.