-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dialyzer can't detect tuple when middleware Tuples is used #109
Comments
The return type spec for I can think of some way to check for Tuples middleware during compilation and adjust the generated typespecs but that would require figuring out a way to make this a general feature (i.e. one could make a custom middleware with custom return values that would need to reflected in the generated typespec). |
I have workaround : I had no knowledge of dialyzer when I wrote |
I would like to keep this issue open for a few days, hoping to get more feedback on this. @teamon , is it okay? |
Definitely, it should stay open. I should have opened this myself ~ two weeks ago 😞 |
Alright, it can be done. Example usagedefmodule Sandbox do
defmodule Client do
use Tesla
end
defmodule TuplesClient do
use Tesla
plug Tesla.Middleware.Tuples
end
def main do
case Client.get("/") do
%{status: _status} -> :ok
end
end
def main_tuple do
case TuplesClient.get("/") do
{:ok, _env} -> :ok
{:error, _reason} -> :error
end
end
end on curent master
on branch dependant-types
Required change to middlewareExplanationI must admit this is quite a hack 💃 Here is the code for https://github.com/teamon/tesla/blob/8e8fd81e212530bb7cb73fc851faac9b54bc1621/lib/tesla.ex#L345-L370 And here is the full diff of changes: So... what do you think? :) |
@ahmadferdous have you got a change to try this out? |
@ahmadferdous I'm going to close this one for now. I think the additional complexity is bigger than gains in this case. Feel free to reopen/comment. |
Hi,
I have a module that uses Tesla and its Tuples middleware.
In that module, Tesla functions are used in the following way:
Spec of
extract_body
expects a tuple with the first element:ok
or:error
. However, when I runmix dialyzer
, it gives the following error:In order for dialyzer to detect that tuples will be returned, do I need to do something additional in the spec or code? What am I missing here?
The text was updated successfully, but these errors were encountered: