#What's the idiomatic way of using `error!`?

15 messages · Page 1 of 1 (latest)

nocturne swan
#

I am trying to call error macro with Err(ref e) => error!(error = e),, e is of type &SessionError.

SessionError is Debug + Display + Error.

But I'm still getting this error:

the trait bevy::bevy_utils::tracing::Value is not implemented for SessionError, which is required by &SessionError: bevy::bevy_utils::tracing::Value

I don't mind just printing a simple text with error! but I'm curious about how to use it.

solar vigil
#

I think that SessionError needs to impl Value or you need to log it differently (maybe error = ?e or error = %e)

nocturne swan
#

Deriving core::error::Error should satisfy Value, no?

#

(I'm using standard features for bevy)

#
the following other types implement trait `bevy::bevy_utils::tracing::Value`:
              &'a T
              &'a mut T
              (dyn StdError + 'static)
              (dyn StdError + Send + 'static)
              (dyn StdError + Send + Sync + 'static)
              (dyn StdError + Sync + 'static)
              Arguments<'a>
              Box<T>
            and 34 others

I am assuming dyn StdError is core::error::Error.

solar vigil
#

Let's not assume but check the docs

nocturne swan
solar vigil
#

If you have a SessionError that is your type. It doesn't become a dyn Error unless you make it one, AFAIK.

nocturne swan
cosmic socket
#

let error: Box<dyn Error> = Box::new(session_error);

nocturne swan
#

strangely this worked

#

Thanks @cosmic socket , @solar vigil

humble rover
#

I think you can use as to cast to a dyn Error without boxing. I'm not super sure