Currently, when logging a panic object, the code logs the panic payload directly. This can result in unclear or unhelpful log output, especially if the panic payload is not a string. To improve the clarity of panic logs, we should convert the panic payload to a string or format it appropriately before logging.
Suggested Fix:
Update the panic logging code to attempt to downcast the panic payload to a &str or String, and fall back to formatting it with Debug if those fail. Here is a code snippet illustrating the proposed change:
let panic_msg = if let Some(s) = panic.downcast_ref::<&str>() {
s.to_string()
} else if let Some(s) = panic.downcast_ref::<String>() {
s.clone()
} else {
format!("{:?}", panic)
};
tracing::error!(
panic = %panic_msg,
?peer_addr,
"connection task panicked"
);
Action Items:
- Refactor the panic logging code as shown above.
- Ensure that all panic logs are clear and provide useful information for debugging.
- Add or update tests if necessary to verify the improved logging behavior.
Issue: #218
I created this issue for @leynos from #215 (comment).
Tips and commands
Getting Help
Currently, when logging a panic object, the code logs the panic payload directly. This can result in unclear or unhelpful log output, especially if the panic payload is not a string. To improve the clarity of panic logs, we should convert the panic payload to a string or format it appropriately before logging.
Suggested Fix:
Update the panic logging code to attempt to downcast the panic payload to a
&strorString, and fall back to formatting it withDebugif those fail. Here is a code snippet illustrating the proposed change:Action Items:
Issue: #218
I created this issue for @leynos from #215 (comment).
Tips and commands
Getting Help