Fix EM101: assign exception string literals to variables#186
Fix EM101: assign exception string literals to variables#186
Conversation
…aising exceptions Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/32f95d07-2615-4b02-8ede-1905999920d8 Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
…r message Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/32f95d07-2615-4b02-8ede-1905999920d8 Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
There was a problem hiding this comment.
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
EM101from[tool.ruff.lint].ignoreinpyproject.toml. - Refactored multiple
raise ...("literal")sites tomsg = "..."; 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"]) | |||
There was a problem hiding this comment.
_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).
| help_msg = shell_command_to_string(self.codeql_cli + ["excute", "--help"]) | |
| help_msg = shell_command_to_string(self.codeql_cli + ["execute", "--help"]) |
| if token: | ||
| return token | ||
| raise RuntimeError("AI_API_TOKEN environment variable is not set.") | ||
| msg = "AI_API_TOKEN environment variable is not set." |
There was a problem hiding this comment.
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.
| msg = "AI_API_TOKEN environment variable is not set." | |
| msg = "AI_API_TOKEN or COPILOT_TOKEN environment variable is not set." |
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].ignorerunner.py,models.py,mcp_transport.py,capi.py— Extracted inline exception strings tomsgvariablesmcp_servers/codeql/client.py— Same, plus fixed a latent bug:"Unsupported output format {fmt}"was a plain string instead of an f-stringmcp_servers/codeql/jsonrpyc/__init__.py— Extracted"RPC Request timed out"to variablePattern applied
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/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: