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

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
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

We're in Beta

About us Mission Statement