Fix dialyzer spec for mock opts#831
Merged
yordis merged 1 commit intoelixir-tesla:masterfrom Mar 6, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the Dialyzer type spec for mock response options in Tesla.Mock. The previous response_opt type only listed :headers and :status, but the underlying response/3 helper passes all options through to struct(Tesla.Env, ...), meaning any Tesla.Env field (except :body, which is set separately) is valid. This caused false Dialyzer errors when users passed options like :method or :url.
Changes:
- Expanded the
@type response_optto include:method,:query, and:urlalongside the existing:headersand:status.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@tomekowal do you mind fixing the commits 🙏🏻 See CI |
81844c6 to
d489c69
Compare
Contributor
Author
|
Fixed the commit message. Thanks for pointing it out! |
yordis
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi!
This change is so small that I figured it will be OK to open a PR directly instead of going through issues.
I recently got a dialyzer error:
for code like this:
I was surprised because those mocks worked.
I traced the problem to the dialyzer spec:
https://github.com/elixir-tesla/tesla/blob/master/lib/tesla/mock.ex#L173
and then the change in the PR. The current spec only says
headersandstatuswhile everything that is inTesla.Envcan be set this way:https://github.com/elixir-tesla/tesla/blob/master/lib/tesla/mock.ex#L198
(except
:bodywhich would be overwritten by the body set as the first parameter tojson(body, opts)call)An alternative way would be to use reflection and say that options are "all Telsa.Env fields except for
:body,__module__and__client__, but I think using reflection could be an overkill.