df_safer_dart
0.22.2, released 3 weeks ago by dev-cetera.com
Functional error handling and safety types for Dart.
WASM-ready
What it does
Enhances structure, safety, and debuggability of Dart code by replacing nullables, thrown exceptions, and unawaited futures with sealed functional types like Option, Result, and Resolvable. It uses a companion lint plugin to enforce safety rules at compile-time.
AI-written summary of version 0.22.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to eliminate try-catch blocks and explicit null-checks in favor of functional pipelines.
- You need strict compiler enforcement for error handling and asynchronous flow safety.
- You want detailed stack traces and breadcrumbs for failures in mission-critical code.
Skip it when
- Your team prefers traditional Dart imperative error handling using try-catch and standard exceptions.
- You are working on a quick prototype where strict functional types add unwanted overhead.
Strengths
- Replaces null risks and exceptions with predictable sealed types (Option, Result, Resolvable).
- Companion linter plugin enforces safety rules like preventing dropped outcomes or unhandled futures.
- Breadcrumb tracking allows you to know precisely where failures originated in a chain.
Weaknesses
- Requires adopting a completely different functional programming style and API paradigm.
- Learning curve for developers unfamiliar with monadic types like flatMap and fold.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
Add dependencies to pubspec.yaml and enable the custom_lint plugin in analysis_options.yaml.
import 'package:df_safer_dart/df_safer_dart.dart';
import 'dart:convert';
Async<Option<String>> notificationSound(int userId) =>
fetchUserData(userId)
.map((body) => UNSAFE(() => jsonDecode(body)))
.map((data) => getFromMap<Map>(data, 'config')
.flatMap((c) => getFromMap<Map>(c, 'notifications'))
.flatMap((n) => getFromMap<String>(n, 'sound')));Works with
Packages commonly used together with df_safer_dart: ones it builds on, ones built on it, and its own family.
- stack_tracedf_safer_dart depends on itProvides parsing, inspection, and readable formatting of Dart stack traces.
- equatabledf_safer_dart depends on itProvides value‑based equality for Dart objects without manual == and hashCode.
- df_logBuilt on df_safer_dartA Dart logging utility offering styled, tag‑filtered, in‑memory logs with JSON export and callbacks.