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…
-
erlang compiler options,
report_warnings, things likenowarn_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.
- if this is the right thing. how can I actually leverage it in elixir. I’ve looked at
-
@compile :nowarn_unused_varsattribute in a module that generates warnings.- This seemed to have no impact…
-
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… -
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
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
I respectfully disagree. Unused variables can be a sign that the developer has misspelled something. That strikes me as being quite useful.
benwilson512
This thread has been necroed just to post a rant. Closing.
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









