bugnano

bugnano

What should I do to my library so that Elixir 1.19 and 1.20 do not produce warnings on libraries that implement behaviours?

Hello everyone.

I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub , a library that allows to implement WebTransport servers in Elixir.

Now, the way that library works, is that it exposes some behaviours, and the application author has to implement callbacks. Standard Elixir stuff.

For example, I have defined a callback handle_close as follows:

 @callback handle_close(stream :: Stream.t(), state :: term()) ::
              {:continue, term()} | :close

and the library calls the handle_close callback in this way:

      def handle_info(:wtransport_stream_closed, {%Stream{} = stream, state}) do
        Logger.debug(":wtransport_stream_closed")

        case handle_close(stream, state) do
          {:continue, new_state} ->
            {:noreply, {stream, new_state}}

          _ ->
            {:stop, :normal, {stream, state}}
        end
      end

which means that I pattern match on the return value of the callback.

The problem is that if the application that uses my library only returns {:continue, new_state}, the other branch of the case statement is never executed, and Elixir 1.19+ issues a warning

     warning: the following clause will never match:

         {:continue, new_state} ->

     because it attempts to match on the result of:

         handle_close(stream, state)

     which has type:

         dynamic(:close)

     type warning found at:
     │
 136 │           {:continue, new_state} ->
     │           ~~~~~~~~~~~~~~~~~~~~~~~~~
     │
     └─ wtransport-elixir/lib/wtransport/stream_handler.ex:136: Server.StreamHandler.handle_info/2

As a library author I have no control on what the application does with its callbacks, so what do I have to do on my library in order to make it work without warnings, regardless of the return value of the callback?

Most Liked

woylie

woylie

This is because your code is within a quote block. You can mark it as generated:

quote generated: true do
end
bugnano

bugnano

Thank you very much, it worked :grinning_face:

Where Next?

Popular in Troubleshooting Top

rayex
When I compile hex package io_ansi_plus, I get error “Codepoint failed”. Why? and why are the “Got:” and “Hint:” codepoints identical? It...
New
ChrisAmelia
Currently reading and experimenting through, which is in 1.6 Chapter 7: Sign up | Phoenix Tutorial (Phoenix 1.6) | Softcover.io In regar...
New
bugnano
Hello everyone. I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub ,...
New
anotherpit
Summary A downstream job that deps on a graft correctly waits for the grafted jobs at one graft level, but stops waiting when the workflo...
New
rathoud96
Environment Elixir 1.18.3-otp-27 / OTP 27.3.4 Oban 2.20.2 Phoenix 1.7.x db_connection 2.8.1 / Postgrex 0.21.1 Infrastructure: Google Cl...
New
hyperoceanic
Having read the book, I’m keen to explore Ash a bit more, but I’m falling at the first hurdle - the creation of a new project. Here’s my...
New
ktayah
Environment Oban Pro: 1.7.6 Oban: 2.22.1 Issue When a sub-workflow built with Workflow.put_context/2 is attached to a parent via ...
New
Lotoen
Hello, I am currently using Elixir 1.18.4 and OTP 27 with Linux Mint 22.3 - Cinnamon 64-bit as my operating system. I came across this er...
New
AstraLuma
Experienced programmer writer her first Elixir, and maybe bit off more than she can chew? I’m trying to start two GenServers, where the ...
New
rayex
For hex package islands_score the source @spec for function format/2 is as such: @spec format(t, keyword) :: :ok Why does it show on 4 ...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement