Fix EM102: extract f-strings from exception constructors#189
Fix EM102: extract f-strings from exception constructors#189
Conversation
…rom suppression list Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/02187caa-75bc-4616-836f-be6e421a1fc8 Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enforces Ruff’s EM102 rule (exception f-strings) by removing the existing suppression in pyproject.toml and refactoring exception raises across the codebase to assign interpolated messages to local variables before constructing exceptions.
Changes:
- Removed
EM102from Ruff’s ignore list so the rule is enforced going forward. - Refactored
raise ... (f"...")patterns intomsg = f"..."followed byraise ...(msg)across multiple modules. - Preserved existing exception chaining (
from e) where present while addressing EM102 violations.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/seclab_taskflow_agent/template_utils.py | Refactors required-env-var error to use a msg variable. |
| src/seclab_taskflow_agent/shell_utils.py | Refactors subprocess failure raise to use a msg variable. |
| src/seclab_taskflow_agent/session.py | Refactors missing-checkpoint error to use a msg variable. |
| src/seclab_taskflow_agent/runner.py | Refactors several validation/template-rendering raises to use msg variables (incl. chained raise). |
| src/seclab_taskflow_agent/models.py | Refactors version validation raise to use a msg variable. |
| src/seclab_taskflow_agent/mcp_utils.py | Refactors MCP transport/path resolution errors to use msg variables. |
| src/seclab_taskflow_agent/mcp_transport.py | Refactors URL/timeout errors (sync + async) to use msg variables. |
| src/seclab_taskflow_agent/mcp_servers/codeql/mcp_server.py | Refactors unsupported language/query/db-path errors to use msg variables. |
| src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/init.py | Refactors multiple validation/dispatch errors to use msg variables. |
| src/seclab_taskflow_agent/mcp_servers/codeql/client.py | Refactors URI/target resolution + wrapping runtime error to use msg variables. |
| src/seclab_taskflow_agent/mcp_lifecycle.py | Refactors unsupported transport error to use a msg variable. |
| src/seclab_taskflow_agent/cli.py | Refactors invalid CLI global parsing error to use a msg variable. |
| src/seclab_taskflow_agent/capi.py | Refactors unsupported endpoint error to use a msg variable. |
| src/seclab_taskflow_agent/available_tools.py | Refactors loader/validation errors to use msg variables. |
| src/seclab_taskflow_agent/agent.py | Refactors missing token env var error to use a msg variable. |
| pyproject.toml | Removes EM102 from Ruff ignores to enforce the rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -635,5 +637,6 @@ def run_query( | |||
| case _: | |||
| raise ValueError("Unsupported output format {fmt}") | |||
There was a problem hiding this comment.
The error message for an unsupported fmt currently uses a plain string literal with {fmt}, so callers will see the braces instead of the actual format value. Capture an interpolated message (e.g., using fmt) into msg and raise ValueError(msg) to keep EM102 satisfied while producing a correct message.
| raise ValueError("Unsupported output format {fmt}") | |
| msg = f"Unsupported output format {fmt}" | |
| raise ValueError(msg) |
EM102 was suppressed in
pyproject.tomlrather than fixed. This removes the suppression and resolves all 43 violations across 16 files.Changes
raisestatements into local variables, e.g.:pyproject.toml: RemovedEM102from theignorelist so the rule is enforced going forward.