fix(security): replace remaining assert statements with proper error handling

Replaced 53 assert statements across 22 files with proper
if/raise patterns (TypeError, ValueError, AssertionError)
to resolve Bandit B101 alerts.
This commit is contained in:
TPTBusiness
2026-05-01 13:49:05 +02:00
parent 9e58c64805
commit a43c443c2e
22 changed files with 116 additions and 69 deletions
+4 -2
View File
@@ -620,7 +620,8 @@ class LocalEnv(Env[ASpecificLocalConf]):
for lp, rp in running_extra_volume.items():
volumes[lp] = rp
assert local_path is not None, "local_path should not be None"
if local_path is None:
raise ValueError("local_path should not be None")
volumes = normalize_volumes(volumes, local_path)
@contextlib.contextmanager
@@ -1472,7 +1473,8 @@ class DockerEnv(Env[DockerConf]):
cpu_count=self.conf.cpu_count, # Set CPU limit
**self._gpu_kwargs(client),
)
assert container is not None # Ensure container was created successfully
if container is None:
raise AssertionError("Docker container was not created successfully")
logs = container.logs(stream=True)
print(Rule("[bold green]Docker Logs Begin[/bold green]", style="dark_orange"))
table = Table(title="Run Info", show_header=False)
+2 -1
View File
@@ -84,7 +84,8 @@ class WorkflowTracker:
# Log timer status if timer is started
if self.loop_base.timer.started:
remain_time = self.loop_base.timer.remain_time()
assert remain_time is not None
if remain_time is None:
raise AssertionError("remain_time should not be None")
mlflow.log_metric("remain_time", remain_time.total_seconds())
mlflow.log_metric(
"remain_percent",