Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of high and works with any version of Elixir.
Explanation
Prefer returning tagged results and handling them with with expressions
that include an explicit else clause at application boundaries.
Examples
Avoid:
user = Repo.get!(User, id)
{:ok, account} = Accounts.fetch_account(user)
raise "boom"Prefer:
with {:ok, user} <- Accounts.fetch_user(id),
{:ok, account} <- Accounts.fetch_account(user) do
{:ok, account}
else
{:error, reason} -> {:error, reason}
endNotes
Path exclusions are matched against the source filename and are intended for generated files or temporary migration areas.
The check uses static AST analysis, so dynamic code generation and macro-expanded code may fall outside its signal.
Options
Configure options in .credo.exs with the check tuple:
%{
configs: [
%{
name: "default",
checks: [
{Bylaw.Credo.Check.Elixir.NoRaise,
[
excluded_paths: ["test/support/"]
]}
]
}
]
}:excluded_paths- List of paths or regex to exclude from this check
Usage
Add this check to Credo's checks: list in .credo.exs:
%{
configs: [
%{
name: "default",
checks: [
{Bylaw.Credo.Check.Elixir.NoRaise, []}
]
}
]
}Check-Specific Parameters
Use the following parameters to configure this check:
:excluded_paths
List of paths or regex to exclude from this check
This parameter defaults to [].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.