sinew_exception 1.0.0
sinew_exception: ^1.0.0 copied to clipboard
SinewException types, handlers, processCall, CrashReporter and Localizer.
sinew_exception #
A coded error model: typed exceptions, guards that create them once, a crash reporter and a localizer.
Every failure is translated once, where it happened, into a SinewException with a code that reads module-layer-function-type, so a support report points at the exact call. Everything above that layer only passes the exception along.
Features #
- Built-in types for connectivity, HTTP statuses, parsing, storage and polling:
NoInternetConnectionException,ValidationException,UnauthorizedException,NotFoundException,ServerException,ParseException,StorageFullExceptionand more processCallandprocessUseCase: guards that turn whatever a block throws into aResult, with yourExceptionHandlers deciding what means whatCrashReporter: where bugs (unexpected and parse failures) are reported,CrashReporter.noneby defaultLocalizeranddisplayMessage: the user-facing text, rendered at display time so a language switch updates an error already on screen
Getting started #
dart pub add sinew_exception
Usage #
final result = await processCall<Order>(
'ORD',
'load',
ExceptionLayer.repository,
[
ExceptionHandler(
(error) => error is FormatException,
(error) => const ParseException('ORD', ExceptionLayer.repository, 'load'),
),
],
() => api.order(7),
);
result.when(
success: (order, message) => show(order),
failure: (error, stackTrace) => print(error.code), // ORD-R-load-DF
);
The full program is in example/main.dart.
Related packages #
Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.
Documentation #
- Usage docs: sinew.srctool.com
- API reference: pub.dev/documentation/sinew_exception
- Source and issues: srctool/sinew-dart
- Design and decisions: the Guide
License #
Apache 2.0, see LICENSE.