Need return to be the end of any relevant check #244

Closed
opened 2026-02-17 14:29:09 -05:00 by sirdog3355 · 1 comment
sirdog3355 commented 2026-02-17 14:29:09 -05:00 (Migrated from github.com)

During a code review executed by Claude Opus 4.6, it advised me that the following codeblock does not stop code execution and it keeps running. This code currently exists in cogs/channel_link.py

@app_commands.guilds(GUILD_ID)
    async def cladd(self, interaction: discord.Interaction, voice_channel: str, text_channel: str):
        
        channel_link = DBChannelLink()

        if self.bot.get_channel(int(text_channel)) == None or self.bot.get_channel(int(voice_channel)) == None:
            await interaction.response.send_message("One of the IDs provided is not a channel ID. Please try again.", ephemeral=True)
            logger.error(f"{interaction.user.name} ({interaction.user.id}) attempted to LINK channels but one of them was not a channel ID.")

        txt_channel = self.bot.get_channel(int(text_channel))
        vc_channel = self.bot.get_channel(int(voice_channel))

        try:
            channel_link.add_link(text_channel, voice_channel)
        except ValueError as e:
            await interaction.response.send_message(e, ephemeral=True)
            logger.error(f"{interaction.user.name} ({interaction.user.id}) got an error when trying to LINK #{vc_channel.name} ({vc_channel.id}) and #{txt_channel.name} ({txt_channel.id}): [{e}]")

This was not detected during edge-case testing as, on the front-end, the error message successfully appears with no other messages. This is because, while code execution does not stop, Discord interprets the await interaction.response.send_message("One of the IDs...") as the only response and so doesn't send others.

I've confirmed this by running the command with bogus IDs and then checking to see if a faulty entry exists via /cl-list. A faulty entry did infact exist.

Need to add return to the end of the the check. I do need to audit the entire codebase, however, to include return anywhere it isnt.

During a code review executed by [Claude Opus 4.6](https://claude.ai/), it advised me that the following codeblock does not stop code execution and it keeps running. This code currently exists in `cogs/channel_link.py` ```py @app_commands.guilds(GUILD_ID) async def cladd(self, interaction: discord.Interaction, voice_channel: str, text_channel: str): channel_link = DBChannelLink() if self.bot.get_channel(int(text_channel)) == None or self.bot.get_channel(int(voice_channel)) == None: await interaction.response.send_message("One of the IDs provided is not a channel ID. Please try again.", ephemeral=True) logger.error(f"{interaction.user.name} ({interaction.user.id}) attempted to LINK channels but one of them was not a channel ID.") txt_channel = self.bot.get_channel(int(text_channel)) vc_channel = self.bot.get_channel(int(voice_channel)) try: channel_link.add_link(text_channel, voice_channel) except ValueError as e: await interaction.response.send_message(e, ephemeral=True) logger.error(f"{interaction.user.name} ({interaction.user.id}) got an error when trying to LINK #{vc_channel.name} ({vc_channel.id}) and #{txt_channel.name} ({txt_channel.id}): [{e}]") ``` This was not detected during edge-case testing as, on the front-end, the error message successfully appears with no other messages. This is because, while code execution does not stop, Discord interprets the `await interaction.response.send_message("One of the IDs...")` as the only response and so doesn't send others. I've confirmed this by running the command with bogus IDs and then checking to see if a faulty entry exists via `/cl-list`. A faulty entry did infact exist. Need to add `return` to the end of the the check. I do need to audit the entire codebase, however, to include `return` anywhere it isnt.
sirdog3355 commented 2026-03-06 23:39:21 -05:00 (Migrated from github.com)

Addressed by #263. Documentation does not need to be updated. Closing.

Addressed by #263. Documentation does not need to be updated. Closing.
Sign in to join this conversation.
No description provided.