tsloughter / grpcbox_plugin

Rebar3 plugin for generating grpcbox behaviours
Apache License 2.0
10 stars 24 forks source link

Behaviour specs #19

Open srstrong opened 2 years ago

srstrong commented 2 years ago

I don't know if I'm reading this wrong, but it doesn't look to me like the generated callbacks in the behaviour modules have the correct type specifications. For example, for a unary call the behaviour says:

-callback unary(ctx:ctx(), my_pb:my_input()) ->
    {ok, my_pb:my_output(), ctx:ctx()} | grpcbox_stream:grpc_error_response().

where grpc_error_response is defined as:

-type grpc_error_response() :: {error, grpc_error(), #{headers => map(),
                                                       trailers => #{}}} |
                               {http_error, {http_status(), unicode:chardata()}, #{headers => map(),
                                                                                   trailers => #{}}} |
                               {error, term()}.

but the code in grpxbox_stream:handle_unary is doing:

    case [make the call] of
        {ok, Response, Ctx2} ->
            State1 = from_ctx(Ctx2),
            send(falsoe, Response, State1);
        E={grpc_error, _} ->
            throw(E);
        E={grpc_extended_error, _} ->
            throw(E)
    end.

when doesn't match a grpc_error_response. I'm using master for both grpcbox_plugin and grpcbox - should these two line up? If so, then I'm happy to do a PR to make the behaviours match the code

tsloughter commented 2 years ago

Thanks, you are right, something is wrong here, there was another issue with the error type specs fixed recently https://github.com/tsloughter/grpcbox/pull/79 -- so seems I need to look at all of these :)