anyhow 0.5.1 copy "anyhow: ^0.5.1" to clipboard
anyhow: ^0.5.1 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());
}

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.
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