Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling Around Scan #116

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions modelscan/modelscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,24 @@ def _scan_source(
scanned = False
for scan_class in self._scanners_to_run:
scanner = scan_class(self._settings) # type: ignore[operator]
scan_results = scanner.scan(
source=source,
data=data,
)

try:
scan_results = scanner.scan(
source=source,
data=data,
)
except Exception as e:
logger.error(
f"Error encountered from scanner {scanner.full_name()} with path {source}: {e}"
)
self._errors.append(
ModelScanError(
scanner.full_name(),
ErrorCategories.MODEL_SCAN,
f"Error encountered from scanner {scanner.full_name()}: {e}",
f"{source}",
)
)

if scan_results is not None:
scanned = True
Expand Down
7 changes: 5 additions & 2 deletions modelscan/scanners/pickle/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ def scan(
if data:
results = scan_numpy(data=data, source=source, settings=self._settings)

with open(source, "rb") as file_io:
results = scan_numpy(data=file_io, source=source, settings=self._settings)
else:
with open(source, "rb") as file_io:
results = scan_numpy(
data=file_io, source=source, settings=self._settings
)

return self.label_results(results)

Expand Down
Loading