I'm playing with this pattern, but it seems like it forces you to have a variant for every upstream error. For instance, I have this DatabaseError:
#[derive(Clone, Debug, Error)]
pub enum DatabaseError {
#[error("database error: {0}")]
Database(String),
#[error("failed to deserialize from DB: {0}")]
Deserialize(String),
#[error("failed to serialize input: {0}")]
Serialize(String),
#[error("unexpected error: {0}")]
Unexpected(String),
}
But I might have 2 or 3 error types that turn into DatabaseError::Serialize. Then I end up doing custom From impls. Then I realize serde might be Serialize or Deserialize, so I'm back where I started.
Though I would like to have that chain of errors, but I haven't figured out how to do the custom impl From yet (or if it ends up being useful in my case, even).
Thanks for the ideas.