NLnetLabs / domain

A DNS library for Rust.

Home Page:https://nlnetlabs.nl/projects/domain/about/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error types don't implement std::error::Error

WhyNotHugo opened this issue · comments

commented

Error types don't implement std::error::Error. This makes it hard to handle errors externally. E.g.: this doesn't work:

let err : Box<dyn std::error::Error> = Box::from(SrvError::LongName);

Due to:

the trait `core::error::Error` is not implemented for `SrvError`

This also breaks usability with libraries like thiserror or anyhow.

There mainly two ways around this:

  1. Manually impl the required traits (mainly Display is missing).
  2. Use thiserror with helper macros to generate these at build time.

It might be a good idea to add assert_impl_all(X, std::error::Error) for all error types.

Note: in case you want to support no_std as mentioned in #179, then core::error::Error would be correct. They are both the same type.

They are supposed to impl std::error::Error if the std feature is enabled. If they aren’t, then that is an oversight and should be fixed.

Currently, we can’t use core::error::Error because it is unstable.

commented

They are supposed to impl std::error::Error if the std feature is enabled. If they aren’t, then that is an oversight and should be fixed.

I'll try and produce a patch for this specific one.

Currently, we can’t use core::error::Error because it is unstable.

Ah, I missed that. It might be some time before it's stable and reasonable to push the MSRV.