Repository: nautechsystems/nautilus_trader
File: nautilus_trader/adapters/dydx/execution.py (Python)

Code before:
                        report_id=UUID4(),
                        enum_parser=self._enum_parser,
                        ts_init=self._clock.timestamp_ns(),
                    )
                    reports.append(report)
        else:
            self._log.error("Failed to generate PositionStatusReports")

        len_reports = len(reports)
        plural = "" if len_reports == 1 else "s"
        self._log.info(f"Received {len(reports)} PositionStatusReport{plural}")
        return reports

    def _handle_ws_message(self, raw: bytes) -> None:  # noqa: C901
        try:
            ws_message = self._decoder_ws_msg_general.decode(raw)
            ws_message_channel = ws_message.channel
            ws_message_type = ws_message.type

            if ws_message_type == "channel_data":
                if ws_message_channel == "v4_block_height":
                    self._handle_block_height_channel_data(raw)
                elif ws_message_channel == "v4_subaccounts":
                    self._handle_subaccounts_channel_data(raw)
                elif ws_message_channel == "v4_markets":
                    self._handle_markets(raw)
            elif ws_message_type == "subscribed":
                if ws_message_channel == "v4_block_height":
                    self._handle_block_height_subscribed(raw)
                elif ws_message_channel == "v4_subaccounts":
                    self._handle_subaccounts_subscribed(raw)
                elif ws_message_channel == "v4_markets":
                    self._handle_markets_subscribed(raw)
            elif ws_message_type == "unsubscribed":
                self._log.info(
                    f"Unsubscribed from channel {ws_message_channel} for {ws_message.id}",
                )
            elif ws_message_type == "connected":
                self._log.info("Websocket connected")
            else:
                self._log.error(f"Unknown message `{ws_message_type}`: {raw.decode()}")
        except Exception as e:
            self._log.error(f"Failed to parse websocket message: {raw.decode()} with error {e}")

    def _handle_block_height_subscribed(self, raw: bytes) -> None:
        try:
            msg: DYDXWsBlockHeightSubscribedData = self._decoder_ws_block_height_subscribed.decode(
                raw,
            )
            self._block_height = int(msg.contents.height)


Review comment (suggestion):
Perhaps add an `else` block which logs an error when a message with an unknown channel is received.

Code after:
                        report_id=UUID4(),
                        enum_parser=self._enum_parser,
                        ts_init=self._clock.timestamp_ns(),
                    )
                    reports.append(report)
        else:
            self._log.error("Failed to generate PositionStatusReports")

        len_reports = len(reports)
        plural = "" if len_reports == 1 else "s"
        self._log.info(f"Received {len(reports)} PositionStatusReport{plural}")
        return reports

    def _handle_ws_message(self, raw: bytes) -> None:  # noqa: C901
        try:
            ws_message = self._decoder_ws_msg_general.decode(raw)
            ws_message_channel = ws_message.channel
            ws_message_type = ws_message.type

            if ws_message_type == "channel_data":
                if ws_message_channel == "v4_block_height":
                    self._handle_block_height_channel_data(raw)
                elif ws_message_channel == "v4_subaccounts":
                    self._handle_subaccounts_channel_data(raw)
                elif ws_message_channel == "v4_markets":
                    self._handle_markets(raw)
                else:
                    self._log.error(f"Unknown message `{ws_message_type}`: {raw.decode()}")
            elif ws_message_type == "subscribed":
                if ws_message_channel == "v4_block_height":
                    self._handle_block_height_subscribed(raw)
                elif ws_message_channel == "v4_subaccounts":
                    self._handle_subaccounts_subscribed(raw)
                elif ws_message_channel == "v4_markets":
                    self._handle_markets_subscribed(raw)
                else:
                    self._log.error(f"Unknown message `{ws_message_type}`: {raw.decode()}")
            elif ws_message_type == "unsubscribed":
                self._log.info(
                    f"Unsubscribed from channel {ws_message_channel} for {ws_message.id}",
                )
            elif ws_message_type == "connected":
                self._log.info("Websocket connected")
            else:
                self._log.error(f"Unknown message `{ws_message_type}`: {raw.decode()}")
        except Exception as e:
            self._log.error(f"Failed to parse websocket message: {raw.decode()} with error {e}")

    def _handle_block_height_subscribed(self, raw: bytes) -> None:
        try:
            msg: DYDXWsBlockHeightSubscribedData = self._decoder_ws_block_height_subscribed.decode(