avoid_get_or_else_swallowing_failure
This rule flags getOrElse on an Either, TaskEither or IOEither whose callback ignores the failure it is given.
Why use this rule
Section titled “Why use this rule”Either.getOrElse hands its callback the Left value. A callback that ignores that parameter throws the failure away: the pipeline carried the reason all the way to the boundary, and the boundary drops it in favour of a default the caller cannot distinguish from a real result.
Sometimes that is exactly right — a cached value, a display fallback, a genuinely optional lookup. But it is a decision, and written as (_) => 0 it does not look like one. Using the parameter, or folding with match, makes the choice visible to the next reader.
Option.getOrElse takes no parameter and is never reported: there is no failure there to discard.
See also: fpdart: Either
final count = result.getOrElse((_) => 0);final other = result.getOrElse((failure) => 0); // named, still discardedUse what you were given:
final count = result.getOrElse((failure) => failure.fallbackCount);Or fold explicitly, so the discard is on the page:
final count = result.match((failure) { log(failure); return 0;}, (value) => value);Known limitations
Section titled “Known limitations”A named parameter that is never read is reported the same as _, since naming it and then ignoring it is the same discard.
Files under test/ are skipped by default — discarding a failure in a fixture is ordinary. Set ignore_tests: false to report them too.
No quick fix is offered: what to do with the failure is the decision the rule is asking for.
Options
Section titled “Options”many_lints: rules: avoid_get_or_else_swallowing_failure: ignore_tests: falserules: avoid_get_or_else_swallowing_failure: ignore_tests: false| Option | Type | Default | Description |
|---|---|---|---|
ignore_tests |
bool | true |
Skip files under test/, where discarding a failure in a fixture is ordinary |
Configuration
Section titled “Configuration”This rule is in the pedantic preset — it is deliberately opinionated, since a
fallback that ignores the failure is often the right call. Turn it on
explicitly:
rules: avoid_get_or_else_swallowing_failure: trueTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_throw_in_fp_callback— A throw inside an fpdart callback escapes the error channel the pipeline is built to carry.prefer_chain_either— chainEither lifts a synchronous Either step for you.avoid_ad_hoc_left_type— A pipeline only composes when every step shares one error type.avoid_bare_await_in_do— Awaiting a raw Future inside a Do block escapes the block’s tracking.