Skip to content

Commit

Permalink
Error Handling Around Scan (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
swashko authored Mar 19, 2024
1 parent 9eb0604 commit 7536ddc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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

0 comments on commit 7536ddc

Please sign in to comment.