Skip to content

Fix EM101: assign exception string literals to variables#186

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-linter-error-em101
Open

Fix EM101: assign exception string literals to variables#186
Copilot wants to merge 4 commits intomainfrom
copilot/fix-linter-error-em101

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Ruff rule EM101 flags string literals passed directly to exception constructors. This resolves all violations across the codebase and removes EM101 from the suppression list in pyproject.toml.

Changes

  • pyproject.toml — Removed "EM101" from [tool.ruff.lint].ignore
  • runner.py, models.py, mcp_transport.py, capi.py — Extracted inline exception strings to msg variables
  • mcp_servers/codeql/client.py — Same, plus fixed a latent bug: "Unsupported output format {fmt}" was a plain string instead of an f-string
  • mcp_servers/codeql/jsonrpyc/__init__.py — Extracted "RPC Request timed out" to variable

Pattern applied

# Before
raise RuntimeError("Process thread did not exit within timeout.")

# After
msg = "Process thread did not exit within timeout."
raise RuntimeError(msg)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • unsupported.example.com
    • Triggering command: /usr/bin/python python -m pytest tests/ -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 2, 2026 15:11
Copilot AI changed the title [WIP] Fix linter error EM101 and remove from suppression list Fix EM101: assign exception string literals to variables Apr 2, 2026
Copilot AI requested a review from kevinbackhouse April 2, 2026 15:13
@kevinbackhouse kevinbackhouse marked this pull request as ready for review April 2, 2026 15:21
Copilot AI review requested due to automatic review settings April 2, 2026 15:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR brings the repository into compliance with Ruff rule EM101 (“exception string literals”), by extracting inline exception messages into local variables and then removing EM101 from the Ruff ignore list so the rule is enforced going forward.

Changes:

  • Removed EM101 from [tool.ruff.lint].ignore in pyproject.toml.
  • Refactored multiple raise ...("literal") sites to msg = "..."; raise ...(msg) across the runtime, models, transport, and CodeQL MCP server code.
  • Fixed a latent formatting bug in the CodeQL client where an “Unsupported output format” message was not interpolating fmt.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/seclab_taskflow_agent/runner.py Replaced inline exception string literals with msg variables in several runtime error paths.
src/seclab_taskflow_agent/models.py Updated validation error raising to use a message variable (EM101 compliance).
src/seclab_taskflow_agent/mcp_transport.py Updated thread-join timeout error raising to use a message variable.
src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/__init__.py Updated RPC timeout error raising to use a message variable.
src/seclab_taskflow_agent/mcp_servers/codeql/client.py Updated several RuntimeError/ValueError message sites for EM101 and fixed one missing interpolation.
src/seclab_taskflow_agent/capi.py Updated missing-token error raising to use a message variable.
pyproject.toml Removed EM101 from the Ruff ignore list to enforce the rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -302,7 +304,8 @@ def _format(self, query):
def _resolve_query_server(self):
help_msg = shell_command_to_string(self.codeql_cli + ["excute", "--help"])
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_resolve_query_server() invokes codeql with subcommand "excute", which appears to be a typo (elsewhere in this file you use "execute"). This will likely cause the help command to fail and incorrectly raise RuntimeError("Legacy server not supported!") even on supported CLIs. Rename the subcommand to "execute" (or reuse the same constant used in _lang_server_contact).

Suggested change
help_msg = shell_command_to_string(self.codeql_cli + ["excute", "--help"])
help_msg = shell_command_to_string(self.codeql_cli + ["execute", "--help"])

Copilot uses AI. Check for mistakes.
if token:
return token
raise RuntimeError("AI_API_TOKEN environment variable is not set.")
msg = "AI_API_TOKEN environment variable is not set."
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_AI_token() falls back to COPILOT_TOKEN, but the raised error message only mentions AI_API_TOKEN. Since this message is user-facing and the function’s docstring mentions both env vars, update the message to include both (e.g., AI_API_TOKEN or COPILOT_TOKEN) to reduce confusion when configuration fails.

Suggested change
msg = "AI_API_TOKEN environment variable is not set."
msg = "AI_API_TOKEN or COPILOT_TOKEN environment variable is not set."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix linter error EM101

3 participants