sinew_exception

pub package License Docs

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, StorageFullException and more
  • processCall and processUseCase: guards that turn whatever a block throws into a Result, with your ExceptionHandlers deciding what means what
  • CrashReporter: where bugs (unexpected and parse failures) are reported, CrashReporter.none by default
  • Localizer and displayMessage: 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.

Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.

Documentation

License

Apache 2.0, see LICENSE.

Libraries

sinew_exception
SinewException types, handlers, processCall, CrashReporter and Localizer.