Skip to content

More sophisticated error handling #28

@ArtiomTr

Description

@ArtiomTr

Lots of places are using Box<dyn std::error::Error> for error types. It is kinda common pattern in rust applications, so that's generally fine, but instead of implementing everything from scratch, it is common to use anyhow crate for errors. It has exactly the same functionality, as Box<dyn std::error::Error>, but with more handy features, like custom errors, assertions, contexts, etc.

Also, there are quite a lot of places, which are using String as error type. This is really non-standard way, and should be replaced with normal errors.

What also needs to be fixed, are panics:

let mut new_historical_hashes = HistoricalBlockHashes::default();
for hash in &self.historical_block_hashes {
    new_historical_hashes.push(*hash).expect("within limit"); // <-----
}

So in general, you should never panic, unless there is some unique/impossible situation, that can never happen. So instead, you should do errors here, and handle them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions