Skip to content

Commit 885bed4

Browse files
Fix EM101 linter errors: assign string literals to variables before raising 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>
1 parent 17111b4 commit 885bed4

7 files changed

Lines changed: 30 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ target-version = "py310"
170170
# deliberate style choices. Rules can be tightened incrementally.
171171
ignore = [
172172
# Style choices — deliberate project conventions
173-
"EM101", # Exception string literals
174173
"EM102", # Exception f-strings
175174
"G004", # Logging f-strings
176175
"T201", # print() used for user output

src/seclab_taskflow_agent/capi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def get_AI_token() -> str:
6161
token = os.getenv("COPILOT_TOKEN")
6262
if token:
6363
return token
64-
raise RuntimeError("AI_API_TOKEN environment variable is not set.")
64+
msg = "AI_API_TOKEN environment variable is not set."
65+
raise RuntimeError(msg)
6566

6667

6768
# assume we are >= python 3.9 for our type hints

src/seclab_taskflow_agent/mcp_servers/codeql/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ def _server_request_run(
194194
template_values: dict | None = None,
195195
):
196196
if not self.active_database:
197-
raise RuntimeError("No Active Database")
197+
msg = "No Active Database"
198+
raise RuntimeError(msg)
198199

199200
if not self.active_connection:
200-
raise RuntimeError("No Active Connection")
201+
msg = "No Active Connection"
202+
raise RuntimeError(msg)
201203

202204
if isinstance(quick_eval_pos, dict):
203205
# A quick eval position contains:
@@ -302,7 +304,8 @@ def _format(self, query):
302304
def _resolve_query_server(self):
303305
help_msg = shell_command_to_string(self.codeql_cli + ["excute", "--help"])
304306
if not re.search("query-server2", help_msg):
305-
raise RuntimeError("Legacy server not supported!")
307+
msg = "Legacy server not supported!"
308+
raise RuntimeError(msg)
306309
return "query-server2"
307310

308311
def _resolve_library_paths(self, query_path):
@@ -463,7 +466,8 @@ def _file_uri_to_path(uri):
463466
# internally the codeql client will resolve both relative and full paths
464467
# regardless of root directory differences
465468
if not uri.startswith("file:///"):
466-
raise ValueError("URI path should be formatted as absolute")
469+
msg = "URI path should be formatted as absolute"
470+
raise ValueError(msg)
467471
# note: don't try to parse paths like "file://a/b" because that returns "/b", should be "file:///a/b"
468472
parsed = urlparse(uri)
469473
if parsed.scheme != "file":
@@ -633,7 +637,8 @@ def run_query(
633637
case "sarif":
634638
result = server._bqrs_to_sarif(bqrs_path, server._query_info(query_path))
635639
case _:
636-
raise ValueError("Unsupported output format {fmt}")
640+
msg = "Unsupported output format {fmt}"
641+
raise ValueError(msg)
637642
except Exception as e:
638643
raise RuntimeError(f"Error in run_query: {e}") from e
639644
return result

src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ def call(
459459
if timeout:
460460
elapsed = time.monotonic() - starting_time
461461
if elapsed > timeout:
462-
raise TimeoutError("RPC Request timed out")
462+
msg = "RPC Request timed out"
463+
raise TimeoutError(msg)
463464

464465
time.sleep(block)
465466
return id

src/seclab_taskflow_agent/mcp_transport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def join_and_raise(self, timeout: float | None = None) -> None:
216216
"""
217217
self.join(timeout)
218218
if self.is_alive():
219-
raise RuntimeError("Process thread did not exit within timeout.")
219+
msg = "Process thread did not exit within timeout."
220+
raise RuntimeError(msg)
220221
if self.exception is not None:
221222
raise self.exception
222223

src/seclab_taskflow_agent/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class TaskDefinition(BaseModel):
106106
@model_validator(mode="after")
107107
def _run_xor_prompt(self) -> TaskDefinition:
108108
if self.run and self.user_prompt:
109-
raise ValueError("shell task ('run') and prompt task ('user_prompt') are mutually exclusive")
109+
msg = "shell task ('run') and prompt task ('user_prompt') are mutually exclusive"
110+
raise ValueError(msg)
110111
return self
111112

112113

src/seclab_taskflow_agent/runner.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def _merge_reusable_task(
105105
if reusable_doc is None:
106106
raise ValueError(f"No such reusable taskflow: {task.uses}")
107107
if len(reusable_doc.taskflow) > 1:
108-
raise ValueError("Reusable taskflows can only contain 1 task")
108+
msg = "Reusable taskflows can only contain 1 task"
109+
raise ValueError(msg)
109110
parent_task = reusable_doc.taskflow[0].task
110111
merged: dict[str, Any] = parent_task.model_dump(by_alias=True, exclude_defaults=True)
111112
current: dict[str, Any] = task.model_dump(by_alias=True, exclude_defaults=True)
@@ -198,14 +199,16 @@ async def _build_prompts_to_run(
198199
raise
199200
except json.JSONDecodeError as exc:
200201
logging.critical(f"Could not parse tool result as JSON: {last_mcp_tool_results[-1][:200]}")
201-
raise ValueError("Tool result is not valid JSON") from exc
202+
msg = "Tool result is not valid JSON"
203+
raise ValueError(msg) from exc
202204

203205
text = last_result.get("text", "")
204206
try:
205207
iterable_result = json.loads(text)
206208
except json.JSONDecodeError as exc:
207209
logging.critical(f"Could not parse result text: {text}")
208-
raise ValueError("Result text is not valid JSON") from exc
210+
msg = "Result text is not valid JSON"
211+
raise ValueError(msg) from exc
209212
try:
210213
iter(iterable_result)
211214
except TypeError:
@@ -403,7 +406,8 @@ async def _run_streamed() -> None:
403406
max_retry -= 1
404407
except RateLimitError:
405408
if rate_limit_backoff == MAX_RATE_LIMIT_BACKOFF:
406-
raise APITimeoutError("Max rate limit backoff reached")
409+
msg = "Max rate limit backoff reached"
410+
raise APITimeoutError(msg)
407411
if rate_limit_backoff > MAX_RATE_LIMIT_BACKOFF:
408412
rate_limit_backoff = MAX_RATE_LIMIT_BACKOFF
409413
else:
@@ -556,7 +560,8 @@ async def on_handoff_hook(context: RunContextWrapper[TContext], agent: Agent[TCo
556560
inputs = task.inputs or {}
557561
task_prompt = task.user_prompt or ""
558562
if run and task_prompt:
559-
raise ValueError("shell task and prompt task are mutually exclusive!")
563+
msg = "shell task and prompt task are mutually exclusive!"
564+
raise ValueError(msg)
560565
must_complete = task.must_complete
561566
max_turns = task.max_steps or DEFAULT_MAX_TURNS
562567
toolboxes_override = task.toolboxes or []
@@ -615,10 +620,11 @@ async def run_prompts(async_task: bool = False, max_concurrent_tasks: int = 5) -
615620
resolved_agents[agent_name] = personality
616621

617622
if not resolved_agents:
618-
raise ValueError(
623+
msg = (
619624
"No agents resolved for this task. "
620625
"Specify a personality with -p or provide an agents list."
621626
)
627+
raise ValueError(msg)
622628

623629
async def _deploy(ra: dict, pp: str) -> bool:
624630
async with semaphore:

0 commit comments

Comments
 (0)