-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange happenings with manual implementation of Valuable
#88
Comments
I believe I've figured out what's going wrong here. Your Since The problem is due to a bug in valuable/valuable-serde/src/lib.rs Line 267 in 1fc2ad5
This is not correct. If a Instead, it should probably record the string representation of the error using |
Currently, `valuable-serde` handles `Value::Error` variants incorrectly. When `valuable-serde` encounters a `Value::Error`, it returns the error immediately as a serialization error: https://github.com/tokio-rs/valuable/blob/1fc2ad50fcae7fc0da81dc40a385c235636ba525/valuable-serde/src/lib.rs#L267 This is _not_ correct. If a `serde` serializer returns an error, this means something has gone wrong while serializing a value. Returning an error makes the serialization fail. However, this is *not* what `valuable`'s `Value::Error` means. `Value::Error` represents that we are _recording a value which happens to be an `Error`_, not that something went wrong _while_ recording the value. This means that `valuable-serde` will currently return an `Error` (indicating that serialization failed) any time it attempts to record an `Error` value, and serialization will fail. This commit changes `valuable-serde` to record the error using its `Display` implementation, using `serde`'s `collect_str` method. Now, `Error`s will be serialized by recording their messages as a string, rather than causing the serialization to fail. Using `collect_str` allows the serializer to write the display representation to its own internal buffer, rather than having to format the error to a temporary `String` beforehand. Fixes #88
Currently, `valuable-serde` handles `Value::Error` variants incorrectly. When `valuable-serde` encounters a `Value::Error`, it returns the error immediately as a serialization error: https://github.com/tokio-rs/valuable/blob/1fc2ad50fcae7fc0da81dc40a385c235636ba525/valuable-serde/src/lib.rs#L267 This is _not_ correct. If a `serde` serializer returns an error, this means something has gone wrong while serializing a value. Returning an error makes the serialization fail. However, this is *not* what `valuable`'s `Value::Error` means. `Value::Error` represents that we are _recording a value which happens to be an `Error`_, not that something went wrong _while_ recording the value. This means that `valuable-serde` will currently return an `Error` (indicating that serialization failed) any time it attempts to record an `Error` value, and serialization will fail. This commit changes `valuable-serde` to record the error using its `Display` implementation, using `serde`'s `collect_str` method. Now, `Error`s will be serialized by recording their messages as a string, rather than causing the serialization to fail. Using `collect_str` allows the serializer to write the display representation to its own internal buffer, rather than having to format the error to a temporary `String` beforehand. Fixes #88
Currently, `valuable-serde` handles `Value::Error` variants incorrectly. When `valuable-serde` encounters a `Value::Error`, it returns the error immediately as a serialization error: https://github.com/tokio-rs/valuable/blob/1fc2ad50fcae7fc0da81dc40a385c235636ba525/valuable-serde/src/lib.rs#L267 This is _not_ correct. If a `serde` serializer returns an error, this means something has gone wrong while serializing a value. Returning an error makes the serialization fail. However, this is *not* what `valuable`'s `Value::Error` means. `Value::Error` represents that we are _recording a value which happens to be an `Error`_, not that something went wrong _while_ recording the value. This means that `valuable-serde` will currently return an `Error` (indicating that serialization failed) any time it attempts to record an `Error` value, and serialization will fail. This commit changes `valuable-serde` to record the error using its `Display` implementation, using `serde`'s `collect_str` method. Now, `Error`s will be serialized by recording their messages as a string, rather than causing the serialization to fail. Using `collect_str` allows the serializer to write the display representation to its own internal buffer, rather than having to format the error to a temporary `String` beforehand. Fixes #88
Currently, `valuable-serde` handles `Value::Error` variants incorrectly. When `valuable-serde` encounters a `Value::Error`, it returns the error immediately as a serialization error: https://github.com/tokio-rs/valuable/blob/1fc2ad50fcae7fc0da81dc40a385c235636ba525/valuable-serde/src/lib.rs#L267 This is _not_ correct. If a `serde` serializer returns an error, this means something has gone wrong while serializing a value. Returning an error makes the serialization fail. However, this is *not* what `valuable`'s `Value::Error` means. `Value::Error` represents that we are _recording a value which happens to be an `Error`_, not that something went wrong _while_ recording the value. This means that `valuable-serde` will currently return an `Error` (indicating that serialization failed) any time it attempts to record an `Error` value, and serialization will fail. This commit changes `valuable-serde` to record the error using its `Display` implementation, using `serde`'s `collect_str` method. Now, `Error`s will be serialized by recording their messages as a string, rather than causing the serialization to fail. Using `collect_str` allows the serializer to write the display representation to its own internal buffer, rather than having to format the error to a temporary `String` beforehand. Fixes #88
When `Format_event::format_event(...)` returns an errror, we are currently silently dropping that Span/Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever a Span/Event is dropped. This patch adds a single `eprintln` line to let the user know that we were unable to format a specific event. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves tokio-rs#1965.
When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. This patch adds a single `eprintln` line to let the user know that we were unable to format a specific event. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves tokio-rs#1965.
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves #1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
…ter (tokio-rs#2102) Motivation: When `Format_event::format_event(...)` returns an error, we are currently silently dropping that Event. tokio-rs/valuable#88 explains one such case in which this was encountered (due to a bug in valuable-serde). We want to be made aware whenever an Event is dropped. Solution: Write to the Writer with an error message to let the user know that we were unable to format a specific event. If writing to the Writer fails, we fall back to writing to stderr. We are not emitting an actual tracing Event, to avoid the risk of a cycle (the new Event could trigger the same formatting error again). Resolves tokio-rs#1965. Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: David Barsky <me@davidbarsky.com>
For the short term, I wanted to make myself a wrapper for
anyhow::Error
, to use the unstable support intracing
and log the values as structured.What happened is that my manual implementation - although seemingly correct, fails to serialize. A different implementation, which stringifies early and uses
#[derive(Valuable)]
works just fine.Because the code is a bit bigger than fits into an issue, I have created a reproduction in a separate repository, with both versions.
cc @hawkw
The text was updated successfully, but these errors were encountered: