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

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
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
anotherpit
A graft inside another graft causes Oban.Pro.Workflow.status to recurse forever. oban_pro 1.7.5 defmodule App.NestedGraftRepro.Test do ...
New
bugnano
Hello everyone. I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub ,...
New
Lotoen
Hi, I’m on Linux Mint 22.3 - Cinnamon 64-bit, and I encountered an error when trying to build an elixir phoenix container 577.1 Reading...
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
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
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
tellemiller
We recently started running Oban with Oban Web on PostgreSQL (AWS RDS gp3) and noticed our oban_jobs buffer cache hit ratio sitting at 65...
New
hakarabakara1
I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I inte...
New

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement