Skip to content

Fix dialyzer spec for mock opts#831

Merged
yordis merged 1 commit intoelixir-tesla:masterfrom
tomekowal:tkowal/fix-dialyzer-spec
Mar 6, 2026
Merged

Fix dialyzer spec for mock opts#831
yordis merged 1 commit intoelixir-tesla:masterfrom
tomekowal:tkowal/fix-dialyzer-spec

Conversation

@tomekowal
Copy link
Copy Markdown
Contributor

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:

The created anonymous function has no local return.

for code like this:

mock = fn %{body: body} ->
  json(body, method: method, url: url, status: 200)
end

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 headers and status while everything that is in Tesla.Env can be set this way:

https://github.com/elixir-tesla/tesla/blob/master/lib/tesla/mock.ex#L198

(except :body which would be overwritten by the body set as the first parameter to json(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.

Copilot AI review requested due to automatic review settings March 5, 2026 15:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_opt to include :method, :query, and :url alongside the existing :headers and :status.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yordis
Copy link
Copy Markdown
Member

yordis commented Mar 5, 2026

@tomekowal do you mind fixing the commits 🙏🏻 See CI

@tomekowal tomekowal force-pushed the tkowal/fix-dialyzer-spec branch from 81844c6 to d489c69 Compare March 6, 2026 08:09
@tomekowal
Copy link
Copy Markdown
Contributor Author

Fixed the commit message. Thanks for pointing it out!

@yordis yordis merged commit 440ec4e into elixir-tesla:master Mar 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants