We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Avoid Making Logger the Last Statement in Functions
5
clicks

Source: nickgnd.com
The article emphasizes the common mistake developers make when concluding a function with a Logger statement in Elixir, which can lead to subtle bugs due to Logger's return value of `:ok`. It illustrates a scenario where a Logger.error could be mistakenly treated as a successful response when actually an error occurs. To address this, the author created a custom Credo check, encapsulated in a script, to flag instances where Logger calls appear as the final statement in function definitions. This check traverses the AST, identifying Logger calls and issuing warnings appropriately, considering various control structures such as if/else and case statements. While the author doubts the frequent utility of this check in real projects, they acknowledge it as an interesting exercise in exploring Elixir's capabilities.
Related posts
© HashMerge 2025