rust-lang-deprecated / failure

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Error management

Programming Languages

rust
11053 projects
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to failure

raygun4android
Android crash reporting provider for Raygun
Stars: ✭ 19 (-98.69%)
Mutual labels:  error-handling
node-graceful-shutdown
Gracefully shutdown your modular NodeJS application.
Stars: ✭ 20 (-98.62%)
Mutual labels:  error-handling
static-404
⚡️ A WordPress plugin to quickly send a 404 for missing static files
Stars: ✭ 24 (-98.34%)
Mutual labels:  error-handling
optionals
Rust-like error handling and options for TypeScript and Deno!
Stars: ✭ 97 (-93.3%)
Mutual labels:  error-handling
kotlin-multiplatform-example
A Kotlin multiplatform example app that targets Android, ReactJS, iOS, JavaFx, and Spring Boot
Stars: ✭ 115 (-92.06%)
Mutual labels:  error-handling
safe
🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: ✭ 15 (-98.96%)
Mutual labels:  error-handling
express-error-slack
Express error handling middleware for reporting error to Slack
Stars: ✭ 14 (-99.03%)
Mutual labels:  error-handling
superagent-intercept
Add functions that will be called during end() e.g. for handling error conditions without having the same code all over the place.
Stars: ✭ 23 (-98.41%)
Mutual labels:  error-handling
custom error
Define custom errors without boilerplate using the custom_error! macro.
Stars: ✭ 70 (-95.17%)
Mutual labels:  error-handling
custom-exception-middleware
Middleware to catch custom or accidental exceptions
Stars: ✭ 30 (-97.93%)
Mutual labels:  error-handling
raygun4py
Python provider for Raygun
Stars: ✭ 18 (-98.76%)
Mutual labels:  error-handling
of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-99.1%)
Mutual labels:  error-handling
babel-errors
Nicer error messages for Babel
Stars: ✭ 15 (-98.96%)
Mutual labels:  error-handling
fortran-error-handler
Comprehensive error framework for applications requiring functional and robust error handling, utilising the power of modern object-oriented Fortran.
Stars: ✭ 19 (-98.69%)
Mutual labels:  error-handling
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (-97.44%)
Mutual labels:  error-handling
go-errors
A super tiny package for error encapsulation in idiomatic Go
Stars: ✭ 14 (-99.03%)
Mutual labels:  error-handling
friendly-error
Show uncaught errors friendly in Node.js.
Stars: ✭ 75 (-94.82%)
Mutual labels:  error-handling
react-error-guard
⚛️An overlay for displaying stack frames based on create-react-app/packages/react-error-overlay
Stars: ✭ 18 (-98.76%)
Mutual labels:  error-handling
result17
A rust like Result type for modern C++
Stars: ✭ 13 (-99.1%)
Mutual labels:  error-handling
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (-98.55%)
Mutual labels:  error-handling

failure - a new error management story

Notice: failure is deprecated. If you liked failure's API, consider using:

  • Anyhow is a good replacement for failure::Error.
  • thiserror is a good, near drop-in replacement for #[derive(Fail)].

Build Status Latest Version docs

failure is designed to make it easier to manage errors in Rust. It is intended to replace error management based on std::error::Error with a new system based on lessons learned over the past several years, including those learned from experience with quick-error and error-chain.

failure provides two core components:

  • Fail: A new trait for custom error types.
  • Error: A struct which any type that implements Fail can be cast into.

Evolution

Failure is currently evolving as a library. First of all there is work going on in Rust itself to fix the error trait secondarily the original plan for Failure towards 1.0 is unlikely to happen in the current form.

As such the original master branch towards 1.0 of failure was removed and master now represents the future iteration steps of 0.1 until it's clear what happens in the stdlib.

The original 1.0 branch can be found in evolution/1.0.

Example

extern crate serde;
extern crate toml;

#[macro_use] extern crate failure;
#[macro_use] extern crate serde_derive;

use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;

use failure::Error;

// This is a new error type that you've created. It represents the ways a
// toolchain could be invalid.
//
// The custom derive for Fail derives an impl of both Fail and Display.
// We don't do any other magic like creating new types.
#[derive(Debug, Fail)]
enum ToolchainError {
    #[fail(display = "invalid toolchain name: {}", name)]
    InvalidToolchainName {
        name: String,
    },
    #[fail(display = "unknown toolchain version: {}", version)]
    UnknownToolchainVersion {
        version: String,
    }
}

pub struct ToolchainId {
    // ... etc
}

impl FromStr for ToolchainId {
    type Err = ToolchainError;

    fn from_str(s: &str) -> Result<ToolchainId, ToolchainError> {
        // ... etc
    }
}

pub type Toolchains = HashMap<ToolchainId, PathBuf>;

// This opens a toml file containing associations between ToolchainIds and
// Paths (the roots of those toolchains).
//
// This could encounter an io Error, a toml parsing error, or a ToolchainError,
// all of them will be thrown into the special Error type
pub fn read_toolchains(path: PathBuf) -> Result<Toolchains, Error>
{
    use std::fs::File;
    use std::io::Read;

    let mut string = String::new();
    File::open(path)?.read_to_string(&mut string)?;

    let toml: HashMap<String, PathBuf> = toml::from_str(&string)?;

    let toolchains = toml.iter().map(|(key, path)| {
        let toolchain_id = key.parse()?;
        Ok((toolchain_id, path))
    }).collect::<Result<Toolchains, ToolchainError>>()?;

    Ok(toolchains)
}

Requirements

Both failure and failure_derive are intended to compile on all stable versions of Rust newer than 1.31.0, as well as the latest beta and the latest nightly. If either crate fails to compile on any version newer than 1.31.0, please open an issue.

failure is no_std compatible, though some aspects of it (primarily the Error type) will not be available in no_std mode.

License

failure is licensed under the terms of the MIT License or the Apache License 2.0, at your choosing.

Code of Conduct

Contribution to the failure crate is organized under the terms of the Contributor Covenant, the maintainer of failure, @withoutboats, promises to intervene to uphold that code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].