Human Errors

Errors which make your users' lives easier
This crate provides an Error type which has been designed to make errors
something which help guide your users through your application rather than
blocking their progress. It has fundamentally been designed with the expectation
that any failure can be mitigated (even if that means cutting a GitHub issue)
and that explaining to your user how to do so is the fastest way to get them
moving again.
Features
- Advice on how to resolve a problem is a fundamental requirement for the creation of an error, making your developers think about the user experience at the point they write the code.
- Wrapping allows you to expose a causal chain which may incorporate advice from multiple layers in the stack - giving users a better sense of what failed and how to fix it.
- Integration with the
std::error::Errortype allows you to wrap anyBox-able error in the causal chain and provide additional context.
Example
use fs;
use ;
The above code might result in an error which, when printed, shows the following:
Oh no! We could not read the contents of the example.txt file.
This was caused by:
File Not Found
To try and fix this, you can:
- Check that the file exists and that you have permission to access it.
Getting Started
The easiest way to construct a human-errors Error is to use the user
and system helper functions. These allow you to quickly create errors
of either kind with a message and advice for how to resolve the issue.
use human_errors;
user;
system;
These methods can also be used to wrap existing errors, adding advice on how to best deal with them.
use fs;
If you find yourself wanting to add a better error message, you can use the wrap_user
and wrap_system methods to add additional context to an existing error.
use fs;
use human_errors;
Working with Results
To make working with Result types easier, we provide the ResultExt trait
which adds several helper methods to the standard Result type. These include
wrap_err_as_user and wrap_err_as_system which allow you to easily convert
any error in a Result into a human-errors Error of the desired kind.
use fs;
use ;