Skip to content

Commit 42a3e0f

Browse files
committed
refactor: Improve error handling and messaging in miniatures and force services; update test cases for clarity
1 parent 1adf524 commit 42a3e0f

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

app/blueprints/miniatures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def add():
141141
"notes": form.get("notes"),
142142
}
143143
flash(
144-
f"Unique ID {unique_id} already exists in Series {series}. Suggested next ID: {next_unique}",
144+
f"""Unique ID {unique_id} already exists in Series {series}.
145+
Suggested next ID: {next_unique}""",
145146
"danger",
146147
)
147148
available_factions = get_distinct_factions()

app/services/force_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ def import_force_from_json(file_path: str) -> dict[str, Any]:
338338

339339
try:
340340
data = json.loads(filepath.read_text(encoding="utf-8"))
341-
except FileNotFoundError:
342-
raise ValueError(f"File not found: {file_path}")
341+
except FileNotFoundError as err:
342+
raise ValueError(f"File not found: {file_path}") from err
343343

344344
force_name = data.get("force_name", "Imported Force")
345345

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,13 @@ def validate_expunged_object(obj, *attributes):
405405
"""
406406
from sqlalchemy.orm.exc import DetachedInstanceError
407407

408-
try:
409-
for attr in attributes:
408+
for attr in attributes:
409+
try:
410410
_ = getattr(obj, attr)
411-
except DetachedInstanceError as e:
412-
raise AssertionError(f"Object {obj} not properly expunged - cannot access {attr}: {e}")
411+
except DetachedInstanceError as e:
412+
raise AssertionError(
413+
f"Object {obj} not properly expunged - cannot access {attr}: {e}"
414+
) from e
413415

414416

415417
def assert_single_active_force(forces):

tests/test_lance_template_service_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_import_creates_from_export(client):
245245
temp_path = f.name
246246

247247
try:
248-
result = import_templates_from_json(temp_path)
248+
import_templates_from_json(temp_path)
249249

250250
templates = get_all_templates()
251251
assert len(templates) == 3
@@ -297,7 +297,7 @@ def test_import_merge_updates_existing(client):
297297
temp_path = f.name
298298

299299
try:
300-
result = import_templates_from_json(temp_path)
300+
import_templates_from_json(temp_path)
301301

302302
templates = get_all_templates()
303303
assert len(templates) == 2 # No new templates created

tests/test_lance_template_service_unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_import_skips_invalid_entries(client):
166166
temp_path = f.name
167167

168168
try:
169-
result = import_templates_from_json(temp_path)
169+
import_templates_from_json(temp_path)
170170

171171
# Only 2 valid templates should be imported
172172
templates = get_all_templates()

0 commit comments

Comments
 (0)