NobbZ
I’ve forked an abondoned hex-package and continue to maintain it under a new name.
The old code-base does provide a macro that we call finalize/0 for the purpose of this thread. This macro does its work depending on some module-attributes which are filled by other macros (which I do not need to explain here, just consider them similar to the test macro of ex_unit).
Now I want to move the functionallity of this finalize/0-macro into __before_compile__/1-macro and add a proper deprecation warning to finalize/0.
Such that a warning is emitted during compiletime when someone still uses finalize/0 and the hint that it is handled automatically in the current version and that the feature will get completely removed with version X. But how? I did not find anything in the documentation.
Trending in Questions
Other Trending 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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Currently I just use
Logger.warn/2to get some output at least, but this doesn’t feel right. I’d prefer a way that makes the compiler aware of the warning, such that someone who compiles with warnings as errors will have a failing build.hubertlepicki
You can do this:
warn.ex:and when compiling you get:
In both cases warning is printed to the stderr while compilation. In first case, however, compilation fails and appropriate shell exit code is set. In second case only warning is printed.
@Edit: Code search results · GitHub
Looks like it’s ok to do that, but better in this form:
arjan
On a more general note, you could write a function decorator for this, like this:
Which you would use like this:
[/end shameless library-plug]
josevalim
TL;DR - Don’t do this. Use
IO.warn(msg, Macro.Env.stacktrace(env)).Please don’t do this.
:elixir_errorsis a private module. It is undocumented. It is internal to Elixir only. It is not meant to be accessed by other libraries besides Elixir. There is no guarantee it will continue working on future releases.Relying on private functions it is very harmful. In the future, if such practices are wide-spread, one of the two things will happen:
We won’t be able to improve Elixir, or improving it will be more complex, because developers are relying on APIs they should not, and we will need to phase them out first
Packages will break on new Elixir versions, which will make it harder for people to migrate to future Elixir versions, or give the impression the ecosystem is fragile (which would be if new Elixir versions are breaking supposedly valid code).
Please don’t rely on private APIs. Not for Elixir, not for other libraries. It is more harmful than you may think.
hubertlepicki
This is great. I am terribly sorry to post misleading message, it was the thing I saw somewhere and adopted.
This is way better, however!
Edit: ah yeah it’s plenty of wrong usage in different libs then:
low hanging fruits if someone wants to make some pull requests.
josevalim
No problem! Although Discourse shows I replied to you, it was really to everyone that is using private APIs, here or on GitHub.
Ajaxdone
I am compiling a big project with many sub projects in it, is it any global setting so I can avoid to add command line args in each and every mix compile?
Compilation failed due to warnings while using the --warnings-as-errors option
especially the build is in a Makefile that called from a gradlew