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

outdated

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());
}

Result order() {
  final user = "Bob";
  final food = "pizza";
  final result = makeFood(food).context("$user ordered.");
  if(result.isOk()){
    return Ok("Order Complete");
  }
  return result;
}

Result<int> makeFood(String order) {
  return makeHamburger().context("order was $order.");
}

Result<int> makeHamburger() {
  if(true) {
    return bail("Hmm something went wrong making the hamburger.");
  }
  return Ok(0);
}

// Output:
// Error: Bob ordered.
//
// Caused by:
// 0: order was pizza.
// 1: Hmm something went wrong making the hamburger.
31
likes
0
points
380
downloads

Publisher

verified publishervoyver.com

Weekly Downloads

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