Skip to content

Commit c31a85f

Browse files
fix: ensure scam list loading handles missing or empty files gracefully
1 parent 31bf30d commit c31a85f

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

phoneint/data/scam_list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
"last_seen": "2024-03-10",
2424
"notes": "Example entry for tests and demos. Replace with your own lawful dataset."
2525
}
26-
]
26+
]

phoneint/gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
def run_gui(settings: PhoneintSettings) -> None:
3737
try:
38-
from PySide6.QtCore import QEvent, QTimer
38+
from PySide6.QtCore import QEvent, QTimer, Qt
3939
from PySide6.QtGui import QGuiApplication
4040
from PySide6.QtWidgets import (
4141
QApplication,

phoneint/reputation/public.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ def _parse_entry(obj: dict[str, object]) -> ScamEntry:
5757

5858

5959
def load_scam_list(path: Path | None = None) -> list[ScamEntry]:
60-
"""
61-
Load scam-list entries.
62-
63-
Args:
64-
path: Optional JSON path. If omitted, loads the packaged sample dataset.
65-
"""
60+
"""Load scam-list entries, defaulting to the packaged sample dataset."""
6661

62+
data: str | None = None
6763
if path is not None:
68-
data = path.read_text(encoding="utf-8")
69-
else:
64+
try:
65+
if path.exists():
66+
raw_text = path.read_text(encoding="utf-8")
67+
if raw_text.strip():
68+
data = raw_text
69+
except OSError:
70+
data = None
71+
72+
if data is None:
7073
data = (
7174
resources.files("phoneint.data").joinpath("scam_list.json").read_text(encoding="utf-8")
7275
)

0 commit comments

Comments
 (0)