arnodirlam

arnodirlam

How to get a warning on undefined module use?

Hi!

I want to match an exception in a rescue block, matching it to several exception modules.
One of the modules is not defined (because I forgot an alias) but neither the compiler, dialyzer, nor credo emit a warning about it.

defmodule ErrorHandler do
  alias Errors.A
  alias Errors.B

  def handle_errors(fun) do
    fun.()
  rescue
    error in A ->
      {:hard_failure, error}

    error in B ->
      {:outage, error}

    # undefined/unaliased module C but no warning emitted
    error in C ->
      {:transient_error, error}
  end
end

Is it possible to have a warning emitted in such cases somehow?
If not, what would be the best place to introduce a warning like this, if this makes sense at all?

Thanks in advance!

Most Liked

josevalim

josevalim

Creator of Elixir

I have posted this on another thread but, for completeness, if you don’t want your code to compile in those cases, you can enable warnings as errors:

[elixirc_options: [warnings_as_errors: true]]

Or if you want to enable it only for xref:

[aliases: ["compile.xref": "compile.xref --warnings-as-errors"]]

PS: @dogweather sorry that you are getting duplicate answers but since people may arrive here from Google, etc, I wanted to post an alternative to get an error on undefined modules.

dogweather

dogweather

Yeah, I found this behavior shocking when I learned about it. The bottom line seems to be that an original BEAM core design is to support a highly dynamic runtime environment; where code can be swapped in and out (“dynamically loaded”). And the issue is, we’re using this system for a whole new set of kinds of apps which are static in nature. E.g., a CRUD Phoenix web app probably is designed to work only with the modules packaged with it at deploy time. And a static code update is easy in the modern era when we can e.g. re-deploy instantly to Heroku without any downtime.

Personally, I’d appreciate a way to flag my app as “non-dynamic”, and then get linking errors at compilation time.

I bumped into your problem in a different context: I want compile errors from router.ex, but everything compiles fine. (?)

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement