Merge pull request #131 from Zeecka/sentry_workers

fix 109
This commit is contained in:
Zeecka
2026-01-03 00:55:51 +01:00
committed by GitHub
5 changed files with 106 additions and 99 deletions
+1
View File
@@ -161,6 +161,7 @@ class SubprocessAnalyzer(ABC):
self.update_result(result)
except Exception as e:
self.update_result({"status": "error", "error": str(e)})
raise
def is_error(self, returncode: int, stdout: str, stderr: str, zip_exist: bool) -> bool:
"""Check if the result is an error."""
-3
View File
@@ -20,7 +20,6 @@ class DecomposerAnalyzer(SubprocessAnalyzer):
def get_results(self, _: Optional[str] = None) -> dict[str, Any]:
"""Analyze an image submission using bits decomposition."""
try:
img = Image.open(self.input_img)
converted = False
@@ -85,8 +84,6 @@ class DecomposerAnalyzer(SubprocessAnalyzer):
)
return output
except Exception as e:
return {"status": "error", "error": str(e)}
def analyze_decomposer(input_img: Path, output_dir: Path) -> None:
+1 -7
View File
@@ -115,7 +115,6 @@ class ResizeAnalyzer(SubprocessAnalyzer):
"""
logs = []
try:
with self.input_img.open("rb") as image:
img_bytes = bytearray(image.read())
try:
@@ -137,9 +136,7 @@ class ResizeAnalyzer(SubprocessAnalyzer):
saved_img_urls = []
# No match found
if not (db_matches := self._lookup_crc()) and not (
db_matches := self._search_height_crc()
):
if not (db_matches := self._lookup_crc()) and not (db_matches := self._search_height_crc()):
return {
"status": "error",
"error": "Failure: No matching dimensions found.",
@@ -160,9 +157,6 @@ class ResizeAnalyzer(SubprocessAnalyzer):
"png_images": saved_img_urls,
}
except Exception as e:
return {"status": "error", "error": str(e)}
def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
"""Analyze an image submission using ResizeAnalyzer."""
+1
View File
@@ -44,6 +44,7 @@ class OpenStegoAnalyzer(SubprocessAnalyzer):
self.update_result(result)
except Exception as e:
self.update_result({"status": "error", "error": str(e)})
raise
def process_output(self, stdout: str, stderr: str) -> str | list[str] | dict[str, str]:
"""Process the stdout/stderr."""
+16 -2
View File
@@ -77,11 +77,25 @@ def analyze_image(submission_hash: str) -> None:
def run_analyzer(analyzer_func: Any, *args: Any) -> None:
"""Run an analyzer function in a separate thread."""
analyzer_name = analyzer_func.__name__.replace("analyze_", "")
try:
analyzer_func(*args)
except Exception as e:
sentry_sdk.capture_exception(e)
print(f"Error in {analyzer_func.__name__}: {e}")
print(f"Error in {analyzer_name}: {e}")
with sentry_sdk.push_scope() as scope:
scope.set_tag("analyzer", analyzer_name)
scope.set_tag("submission_hash", submission_hash)
scope.set_context(
"analyzer_info",
{
"tool": analyzer_name,
"image_path": str(img_path),
"result_path": str(result_path),
"filename": submission.filename,
"deep_analysis": submission.deep_analysis,
},
)
scope.fingerprint = ["analyzer-error", analyzer_name]
sentry_sdk.capture_exception(e)
analyzers = [