vrod
I have put some module attributes in my tests for easier reference, like this
@example Application.fetch_env!(:my_app, :thing)
but I notice I get errors when I run mix credo --strict:
Module attribute @example makes use of unsafe Application configuration call Application.fetch_env!/2
I am not understanding why this is unsafe?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
The value of the
@exampleattribute will be set at compile time and cannot be changed later. This is “unsafe” because it is easy to mistakenly think that it will follow the value configured at runtime, for example inconfig/runtime.exs, leading to hard to track errors.If you intend to set such a value at compile time, use Application.compile_env/3 available since Elixir 1.10.
vrod
Thank you for the explanation. I am still not sure why confusing == unsafe? This would means that many languages are “unsafe” haha. My understanding is that anything outside of a
do…endblock is evaluated at compile-time. But maybe this is my bad understanding – maybeApplication.compile_env/3does not works this way?Is possible to use ENV variable to inject code that gets compiled into the module in this way? For example
and then read that into a module or something like this?
Nicd
It’s possible but you would have to go out of your way to make it possible.
The meaning of “unsafe” here is different. The reason is that code like that can be confusing to a developer. They may expect that after they have built the application into a Mix release and transferred that to the server, that they can still change the value of the module attribute by changing the config, for example in
config/runtime.exs. But because module attributes are handled at compile time, this is not possible. So they may waste a lot of time not knowing why the config is not being read, or even not notice the problem at all until it causes a bug later.What
compile_envdoes is store the value at compile time, but also check at startup if there is another value configured (like inconfig/runtime.exs). If so, it will raise an error, thus alerting the developers that they have misunderstood how the config works and that they need to correct the issue.You can find more here: Elixir v1.10 released - The Elixir programming language