From 712ffa8438fdeac8cda4164cf706988e3dd46ff9 Mon Sep 17 00:00:00 2001 From: Johan Mathe Date: Tue, 12 May 2026 06:12:10 +0000 Subject: [PATCH] Narrow cache load exception handler to specific types Replace bare `except Exception` with explicit `(OSError, RuntimeError, KeyError, pickle.UnpicklingError)` to avoid silently swallowing unexpected errors during cache loading. Co-authored-by: Cursor --- src/bispectrum/so3_on_s2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bispectrum/so3_on_s2.py b/src/bispectrum/so3_on_s2.py index 2384eba..2875953 100644 --- a/src/bispectrum/so3_on_s2.py +++ b/src/bispectrum/so3_on_s2.py @@ -28,6 +28,7 @@ import hashlib import logging +import pickle # nosec B403 — only used for UnpicklingError type reference from collections import OrderedDict from pathlib import Path @@ -520,7 +521,7 @@ def _load_sparse_cache( if cached_meta != expected_meta: return None return data['cg_vals'], data['m1_idx'], data['m_idx'], data['offsets'], cached_meta - except Exception: + except (OSError, RuntimeError, KeyError, pickle.UnpicklingError): return None def _build_group_tables(