Skip to content

Feature Request: Add Debug bound to Error types for Database trait #1674

@prestwich

Description

@prestwich

Currently downstream errors containing Db::Error have to add manual bounds for Debug if they want any printing strategy. However, Debug is derived or impld for all current errors used in revm. This would be a breaking change, however it is unlikely that any downstream implementors have non-Debug error types (I checked the foundry fork DB and they're already Debug)

This affects EVMError<Db::Error> because it derives Debug and therefore has no Debug impl unless the inner Db::Error has a Debug bound

affected traits:

  • Database
  • DatabaseRef
  • State
  • StateRef
  • BlockHash
  • BlockHashRef

What I want to do:

// broken code
#[derive(Debug, thiserror::Error)]
pub enum Error<Db> 
where
    Db: Database
{
    // results in an error 
    // `EvmError<Db::Error>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    #[error("{0:?}"]
    Evm(EVMError<Db::Error>),
    ...
}

What I have to do instead:

#[derive(Debug, thiserror::Error)]
pub enum Error<Db> 
where
    Db: Database
    // this bound holds for all current Database implementors, but must be manually written by consumers
    Db::Error: Debug,
{
    #[error("{0:?}"]
    Evm(EVMError<Db::Error>),
    ...
}

the same is true of std::error::Error, however:

  • this approach does not dovetail with the crates extern crate alloc as std strategy for no_std support
  • it would require an intermediary trait ErrBound to handle changing the bound for std/no_std
  • there would need to be a cfg(feature = "std") implementation of std::error::Error for DatabaseComponentError

so while adding a std::error::Error it seems like supporting a bound of std::error::Error would be much more invasive, while adding Debug is non-invasive

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or lib ability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions