Logging in the implementation of the From trait

Since using the '?' operator is idiomatic Rust, and we can implement the From trait to convert from a dependency's error into our domain error model, is it a good idea to do some logging in the implementation of such trait?


impl From<someDependency::Error> for MyDomainError {
  fn from(error: someDependency::Error) -> MyDomainError {
    error!("Something wrong happened with someDependency. Error: {:?}", error);

I would not put logging there.


If you are logging every time an error gets converted from one type to another, won't that emit a bunch of intermediate log statements as ? passes the error up the call stack?

From an idiomatic perspective, it is also normally expected that From implementations are side-effect free.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.