crashfy:untuple/1 strips {ok, _} tuple result of behavior functions #20

stwind opened this Issue Jul 30, 2013 · 3 comments


None yet

2 participants


Most of time in my cases a mock behavior function returns a {ok, _} or {error, _} tuple as result.

But sel_gen_server:call will by default untuple the result to determine it is an exception or not, so to get around this I have to wrap the result with another {ok, _} layer. Like:

f(Fun) ->
    {arity, Arity} = erlang:fun_info(Fun, arity),
    f(Arity, Fun).

f(0, Fun) -> fun() -> {ok, Fun()} end;
f(1, Fun) -> fun(A) -> {ok, Fun(A)} end;
f(2, Fun) -> fun(A,B) -> {ok, Fun(A,B)} end;
f(3, Fun) -> fun(A,B,C) -> {ok, Fun(A,B,C)} end;
f(4, Fun) -> fun(A,B,C,D) -> {ok, Fun(A,B,C,D)} end;
f(5, Fun) -> fun(A,B,C,D,E) -> {ok, Fun(A,B,C,D,E)} end;
f(6, Fun) -> fun(A,B,C,D,E,F) -> {ok, Fun(A,B,C,D,E,F)} end;
f(7, Fun) -> fun(A,B,C,D,E,F,G) -> {ok, Fun(A,B,C,D,E,F,G)} end.

And here is my typical setup of moka:

I think here just using a built-in gen_server:call will be fine

@samuelrivas samuelrivas was assigned Jul 30, 2013

It is fixed in the branch wip-tagged-returns. I will merge it to master later


Should be fixed in 1.0.3. It will break your tests (sorry about that) but since it was actually a bug I thought that increasing the patch level would be more appropriate than bumping the major version.

Thanks for the bug report!


This has been closed forever ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment