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.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
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
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement