Skip to content

Fix EM102: extract f-strings from exception constructors#189

Open
Copilot wants to merge 2 commits intomainfrom
copilot/em102-fix-linter-error
Open

Fix EM102: extract f-strings from exception constructors#189
Copilot wants to merge 2 commits intomainfrom
copilot/em102-fix-linter-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

EM102 was suppressed in pyproject.toml rather than fixed. This removes the suppression and resolves all 43 violations across 16 files.

Changes

  • 16 source files: Extracted inline f-strings from raise statements into local variables, e.g.:
    # Before
    raise RuntimeError(f"Token env var {token!r} is not set")
    
    # After
    msg = f"Token env var {token!r} is not set"
    raise RuntimeError(msg)
  • pyproject.toml: Removed EM102 from the ignore list so the rule is enforced going forward.

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
…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>
Copilot AI changed the title [WIP] Fix linter error EM102 and remove from suppression list Fix EM102: extract f-strings from exception constructors 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:23
Copilot AI review requested due to automatic review settings April 2, 2026 15:23
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 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 EM102 from Ruff’s ignore list so the rule is enforced going forward.
  • Refactored raise ... (f"...") patterns into msg = f"..." followed by raise ...(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}")
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.

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.

Suggested change
raise ValueError("Unsupported output format {fmt}")
msg = f"Unsupported output format {fmt}"
raise ValueError(msg)

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.

EM102

3 participants