I encounter situations where unwrap_err().downcast_ref() on a miette::Result always returns None despite the correct error type being contained. The situation typically happens in tests where the error type that I'm trying to downcast to is defined in the same workspace member / package. If the error type is defined in another workspace member, then downcast_ref seems to work just fine. I'm wondering why this is the case and whether there are specific limitations that need to be considered.
My error types are typically defined as follows:
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Error, Diagnostic)]
pub enum MyError {
#[error("some error")]
#[diagnostic(code(myerror::some_error))]
SomeError,
}
And tests that I'm referring to have the following structure:
#[cfg(test)]
mod tests {
#[test]
fn test_some_error() {
assert_eq!(do_something().unwrap_err().downcast_ref(), Some(&MyError::SomeError));
}
}
where do_something() returns a miette::Result.
I encounter situations where
unwrap_err().downcast_ref()on amiette::Resultalways returnsNonedespite the correct error type being contained. The situation typically happens in tests where the error type that I'm trying to downcast to is defined in the same workspace member / package. If the error type is defined in another workspace member, thendowncast_refseems to work just fine. I'm wondering why this is the case and whether there are specific limitations that need to be considered.My error types are typically defined as follows:
And tests that I'm referring to have the following structure:
where
do_something()returns amiette::Result.