estack-elixir
Elixir idioms
Read the project's toolchain and formatter configuration. Use APIs supported by the installed Elixir/OTP versions; avoid blanket dependency replacements on the basis of newer standard-library features.
Control flow and contracts
Use function heads and pattern matching when they clarify shape or distinct cases. Use if for simple boolean branches, case for alternatives, and with for sequential fallible operations. Avoid deeply nested branches, but do not turn every conditional into a new function.
Ensure a with failure identifies the failing operation when error shapes overlap. Preserve established public return contracts; expected fallible operations commonly return {:ok, value} or {:error, reason}. Bang functions are appropriate when failure should terminate the current operation.
Handle expected errors explicitly. Let unexpected process failures reach appropriate supervision; a restarted process does not restore in-memory state or undo external side effects.
Exceptions and resources
Rescue only errors you can meaningfully handle, naming their types. Avoid broad rescues that convert programmer defects into success. Preserve stacktraces with reraise error, __STACKTRACE__ when rethrowing.
Prefer resource-owning APIs. This complete function closes the file even if the callback raises: