Git Product home page Git Product logo

pisserror's Introduction

pisserror

A golden replacement for thiserror.

Usage

You'll likely find pisserror to be pretty familiar. As with thiserror, it derives Error for any enum you give to it. Here's a sample of its current usage:

use pisserror::Error;
use std::error::Error; // we don't mess with your prelude :D

#[derive(Debug, Error)]
pub enum DatabaseError {
    #[error("encountered a disk error. see: {_0}")]
    DiskError(#[from] std::io::Error),
    #[error("key `{_0}` has no matching data records")]
    KeyNotFound(String),
    #[error("attempted to store a malformed header. expected: `{expected:?}`. got: `{got:?}`")]
    MalformedHeader {
        expected: String,
        got: String,
    },
    #[error("other error: {_0}")]
    Other(String),
}

Feature Requests and Problems

If there's something wrong or missing, please create a GitHub issue! Make sure to thoroughly describe your intentions.

Contributions

Contributions are welcome! Please create a PR and explain the changes you made.

There are a few ground rules, though:

  • All contributions are bound by the license.
  • Commits must be in Conventional Commits format. Feel free to interpret the rules a bit, though!
  • Document and test your work.

Making a Release

The only note I have for now is to generate the README using cargo-rdme. The crate includes a configuration file for this tool, so it should just work.

pisserror's People

Contributors

onkoe avatar

Watchers

Lucian avatar  avatar  avatar

pisserror's Issues

disallow `#[from]` attr on variants with multiple fields

to get an UserError::Variant from some other::ErrorType, we MUST be able to make a UserError::Variant directly from the other::ErrorType

otherwise, we can't construct Variant from ErrorType, as Variant has more fields.

(well, that could technically work if all of Variant's other fields are Default, but that seems error-prone)

allow from variants to skip the error attr's message

in other words, make this valid:

use pisserror::Error;
use std::error::Error;

#[derive(Debug, Error)]
enum MyError {
    #[error]
    VariantWithFromField(#[from] std::io::Error),
    #[error("message has to be here: {_0}")]
    NormalVariant(i32),
}

refactor to a stepped design

basically:

  • make a struct that has all the data we collect
    • a struct with implementations like impl PissError<FromStep> would much-reduce the amount of args we pass around. (same with VariantType enum)
    • these impls can (and should) be in different files, modules of lib.rs
  • run all the steps according to the type system using PhantomData
    • this might need some additional considerations, as the steps might become a little intermingled.
      • for example, From's outputs also influence how Error is implemented.
      • for now, that's fine. but what if they all rely on each other? design carefully!

split the `match_header` function

that's to account for other uses, like when constructing variants directly

the module would now contain:

// mod: variant

pub(fn) construct_variant_full_path(...) -> syn::Result<TokenStream2> {
    // do what we already do, but without the placeholders
    // ...
}

pub(crate) make_match_head(...) -> syn::Result<TokenStream2> {
    // use create_variant... here
    // make placeholders (either `(_, _, etc.)` or `{..}`
    // ...
}

support non-exhaustive enums

maybe just look for the attribute? otherwise there might be some weird way to tell. dear god i hope the attribute works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.