Skip to content

Commit 0d21426

Browse files
fix(project_creator): Wrap the iteration in the try/except as well
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Amilcar Lucas <amilcar.lucas@iav.de>
1 parent 88bc6be commit 0d21426

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

ardupilot_methodic_configurator/data_model_vehicle_project_creator.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,17 @@ def next_import_filename(vehicle_dir: str) -> str:
430430
"""Return the next available numbered parameter filename for imported log parameters."""
431431
highest_prefix = 0
432432
try:
433-
directory_iter = Path(vehicle_dir).iterdir()
433+
for file_path in Path(vehicle_dir).iterdir():
434+
if not file_path.is_file() or file_path.suffix != ".param":
435+
continue
436+
prefix = file_path.name[:2]
437+
if prefix.isdigit():
438+
highest_prefix = max(highest_prefix, int(prefix))
434439
except OSError as exc:
435440
msg = _("Could not scan the vehicle directory for imported parameter files: {vehicle_dir}. {error}").format(
436441
vehicle_dir=vehicle_dir, error=str(exc)
437442
)
438443
raise VehicleProjectCreationError(_("Parameter import"), msg) from exc
439-
440-
for file_path in directory_iter:
441-
if not file_path.is_file() or file_path.suffix != ".param":
442-
continue
443-
prefix = file_path.name[:2]
444-
if prefix.isdigit():
445-
highest_prefix = max(highest_prefix, int(prefix))
446-
447444
next_prefix = highest_prefix + 1
448445
if next_prefix > 99:
449446
msg = _("Could not create an import parameter file because no numbered slot is available in {vehicle_dir}")

0 commit comments

Comments
 (0)