phewitt

phewitt

How can I Suppress warnings! I've been looking for a while

I want to know how to suppress errors in elixir. Ideally a few ways. Fixing them is not an option. We are slowly fixing them.

I’m currently working in a 7 year old umbrella project with many thousands of warnings, thousands of files. I’ve tried both our current elixir 1.15.6-otp-26 and elixir 1.16.0-otp-26. Which the newer version does have nicer looking errors, but is still not what i’m looking for. I’m wanting to optionally suppress the warnings when running tests or trying to identify compile errors locally. Ideally with a flag or shell var so that I can keep it enabled for ElixirLS.

The main motivation behind this is that the REAL errors get drowned in the sea of warnings. I literally have to use the search feature within my terminal to try and find the error. However, even this is terrible because a lot of the warnings include err or error which makes searching difficult.

I feel like in previous versions (i think ~1.14) of elixir the errors would short circuit compilation which at least left the error at the bottom of the output instead of hidden in the middle.

Given this context the best solution I can think of is leveraging compiler flags to minimize or suppress the warnings explicitly when running tests / iex locally. I’ve found a few things that seem like they may help, but I don’t know how to actually enable them / pass them to the erlang compiler.

Things i’ve sort of found, but have not figured out how to use correctly. A couple things i’ve looked at…

  1. erlang compiler options, report_warnings , things like nowarn_unused_vars

    • if this is the right thing. how can I actually leverage it in elixir. I’ve looked at
      ERL_COMPILER_OPTIONS, but can’t seem to get it do do anything.
  2. @compile :nowarn_unused_vars attribute in a module that generates warnings.

    • This seemed to have no impact…
  3. Mix compile options, --no-all-warnings. I don’t think this is even what i’m looking for but I tried it. or any compile option that might help…

  4. My coworker literally has a script to grep through the output to help filter down to the errors. I would hate for this to be our only solution…

External links that are related.

What’s blown my mind the most about this is that I feel nearly alone looking at a solution to this. I feel configuring the output of a compiler is a pretty important thing.

Anyhow, hope someone can help! Until then i’ll continue my trash workflow of swimming through warnings.

Thank You!

Marked As Solved

LostKobrakai

LostKobrakai

It wasn’t a short circuit, but afaik some changes in ordering of IO. But indeed that changed at some point.

There’s explicitly no way to do that afaik. It’s not a nobody is interested in this, but iirc an active choice made by the core team to not have a setting for that.

Also Liked

Onor.io

Onor.io

I respectfully disagree. Unused variables can be a sign that the developer has misspelled something. That strikes me as being quite useful.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This thread has been necroed just to post a rant. Closing.

Onor.io

Onor.io

You know I actually wished more languages took the approach of not allowing warnings to be suppressed (or at least developers were forced to deal with them). Think about what a warning is (at least in languages like C and C++). A warning is something the compiler author feels needs to be brought to your attention. Maybe you’re intentionally casting a 64-bit integer to a 32-bit unsigned integer (to offer one ridiculous example) which is legal but maybe not what you meant to do.

I love the fact that the same people who insist on 100% test coverage never bother to turn the warning level to 4 and never bother to have their warnings treated as errors. To me this is a simple, cheap way to catch potential bugs at compile time. Sorry–I’m digressing.

You’re facing the result of 7 years of people not dealing with warnings. Yes, it’s a pain in the ass to deal with all those warnings when something you want to know about may be hidden but ignoring them is not really a great answer either.

I once saw a bug in some C++ code that came down to this:

if (x = 1) 
{

Of course what they meant to type was if(x == 1) and the compiler warned them about assignment in the conditional test but they had ignored compiler warnings (for years as far as I could tell). Something like this jumps right out when I type it on a line by itself but buried in thousands of lines of code, it’s a bit harder to catch. At any rate, I set the C++ compiler to treat warnings as errors and this popped right out.

Ignoring warnings is a path to large chunks of technical debt (to say the least). Bite the bullet and get rid of the warnings that have built up over 7 years. I suspect the reason you don’t want to deal with the warnings is that you haven’t got time–tight deadline or something of that sort. But if you suppress or continue to ignore warnings you’re just kicking the can down the road. I mean how do you know that those warnings you’re trying to suppress aren’t pointing out real issues in your code?

Just my $.02.

peixian

peixian

I suppress warnings because I hate the recent IO diagnostic change that forces me to search for errors within a sea of warnings, instead of putting the error as the last line when the compilation terminates.

phewitt

phewitt

I knew this type of response would show up here like all the other places… Again, in a vacuum I agree with you. Warnings can be helpful. If I started a fresh project I would probably use the warning-as-error or whatever flag to help keep them from happening at all (however idk what you would do if you actually had an intentional warning).

We have been actively addressing them as we go. Typically if we touch a file that has some we address them. I don’t want them always suppressed, I want to optionally disable them. I love my IDE underlining it in yellow, I want CI showing it, I want to see it when I build sometimes too. I want the flexibility to leverage it when it’s useful and turn it off when it’s literally not useful.

I want to be pragmatic with my solution I have and not dogmatic about all warnings are or are not the enemy. I believe there is nuance in most things, this included.

It totally could be signs of “real” issues. But clearly not any major issues because they’ve been there for years and our system has served millions of users just fine with all of them there! Like worrying about an unused variable is hardly a cause for concern generally… and yes some very niche edge case it could help identify, but we are past the point of no return. To me there is a difference between like theoretically a problem and actually a problem, and most of our warnings are theoretically a problem.

Where Next?

Popular in Questions Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
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

We're in Beta

About us Mission Statement