smite-scenarios: log messages in name(type) format - #194
Conversation
erickcestari
left a comment
There was a problem hiding this comment.
I like the idea to make the logs more self-describing
Concept ACK 667aae8
|
Concept ACK. I think a much simpler way is to implement the |
667aae8 to
a56bfc7
Compare
|
addressed feedback in a56bfc7:
|
a56bfc7 to
33a0f32
Compare
| other => panic!( | ||
| "expected {}, got {other}", | ||
| msg_type::MessageType(msg_type::OPEN_CHANNEL) | ||
| ), |
There was a problem hiding this comment.
Nit: we could simplify all these panics
| other => panic!( | |
| "expected {}, got {other}", | |
| msg_type::MessageType(msg_type::OPEN_CHANNEL) | |
| ), | |
| other => panic!("expected open_channel, got {other}"), |
| for (msg, name, ty) in cases { | ||
| assert_eq!(msg.msg_type(), ty, "wrong type number for {name}"); | ||
| assert_eq!(msg.msg_name(), name, "wrong type name for {ty}"); | ||
| } |
There was a problem hiding this comment.
| for (msg, name, ty) in cases { | |
| assert_eq!(msg.msg_type(), ty, "wrong type number for {name}"); | |
| assert_eq!(msg.msg_name(), name, "wrong type name for {ty}"); | |
| } | |
| for (msg, name, ty) in cases { | |
| assert_eq!(msg.msg_type(), ty, "wrong type number for {name}"); | |
| assert_eq!(msg.msg_name(), name, "wrong type name for {ty}"); | |
| assert_eq!(msg.to_string(), format!("{name}({ty})")); | |
| assert_eq!(msg_type::MessageType(ty).to_string(), format!("{name}({ty})")); | |
| } |
| impl std::fmt::Display for Message { | ||
| /// Formats as `name(type)`, e.g. `open_channel(32)`. | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| write!(f, "{}({})", self.msg_name(), self.msg_type()) |
There was a problem hiding this comment.
| write!(f, "{}({})", self.msg_name(), self.msg_type()) | |
| write!(f, "{}", msg_type::MessageType(self.msg_type())) |
| }, | ||
| } | ||
|
|
||
| impl std::fmt::Display for Message { |
There was a problem hiding this comment.
Nit: let's move this to just after the impl Message block below.
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct MessageType(pub u16); |
There was a problem hiding this comment.
Now we're using MessageType in some places and u16 in others. I think it would be a bit cleaner if we refactored to use MessageType everywhere. For example, the msg_type::OPEN_CHANNEL and other constants could all be MessageTypes, UnexexpectedMessage errors can contain MessageTypes, and Message::msg_type can return a MessageType.
|
We should also be able to get rid of the |
erickcestari
left a comment
There was a problem hiding this comment.
Probably a follow-up PR, but another thing that might be useful for debugging is to log the warning and error data field as ASCII.
I found this quite useful. This changes the logs like this:
and
WDYT? Concept ACK?