diff --git a/ipv8/community.py b/ipv8/community.py index 0237ee39e..4c0dc507e 100644 --- a/ipv8/community.py +++ b/ipv8/community.py @@ -187,15 +187,19 @@ def add_message_handler(self, msg_num: int | type[Payload], callback: MessageHan actual_msg_num: int = 256 if not isinstance(msg_num, int): if not hasattr(msg_num, "msg_id"): - raise RuntimeError(f"Attempted to add a handler for Payload {msg_num}, which does not specify a msg_id!") + msg = f"Attempted to add a handler for Payload {msg_num}, which does not specify a msg_id!" + raise RuntimeError(msg) actual_msg_num = cast(int, msg_num.msg_id) # type: ignore[attr-defined] else: if msg_num < 0 or msg_num > 255: - raise RuntimeError(f"Attempted to add a handler for message number {msg_num}, which is not a byte!") + msg = f"Attempted to add a handler for message number {msg_num}, which is not a byte!" + raise RuntimeError(msg) actual_msg_num = msg_num if self.decode_map[actual_msg_num]: - raise RuntimeError(f"Attempted to add a handler for message number {actual_msg_num}, already mapped to {self.decode_map[actual_msg_num]}!") + msg = (f"Attempted to add a handler for message number {actual_msg_num}, " + f"already mapped to {self.decode_map[actual_msg_num]}!") + raise RuntimeError(msg) self.decode_map[actual_msg_num] = callback def on_deprecated_message(self, source_address: Address, data: bytes) -> None: