anyhow 0.6.2 copy "anyhow: ^0.6.2" to clipboard
anyhow: ^0.6.2 copied to clipboard

Inspired by Rust's "anyhow" crate, this Dart package provides versatile error handling, implementing Rust's Result monad and "anyhow" crate functionality

example/main.dart

import 'package:anyhow/anyhow.dart';

void main() {
  print(order("Bob", 1));
}

Result<String> order(String user, int orderNumber) {
  final result = makeFood(orderNumber).context("$user ordered.");
  switch (result) {
    case Ok(:final ok):
      return Ok("Order of $ok is complete for $user");
    case Err():
      return result;
  }
}

Result<String> makeFood(int orderNumber) {
  if (orderNumber == 1) {
    return makeHamburger().context("order was $orderNumber.");
  } else {
    return Ok("pasta");
  }
}

Result<String> makeHamburger() {
  return bail("Hmm something went wrong making the hamburger.");
}

//Output:
// Error: Bob ordered.
//
// Caused by:
//  0: order was 1.
//  1: Hmm something went wrong making the hamburger.
19
likes
0
pub points
57%
popularity

Publisher

verified publishervoyver.com

Inspired by Rust's "anyhow" crate, this Dart package provides versatile error handling, implementing Rust's Result monad and "anyhow" crate functionality

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on anyhow