Minifigures commited on
Commit
d1a69de
·
verified ·
1 Parent(s): 8109690

chore: diagnostics (app/ml/imaging/real.py)

Browse files
Files changed (1) hide show
  1. app/ml/imaging/real.py +10 -2
app/ml/imaging/real.py CHANGED
@@ -128,8 +128,16 @@ def _load_grayscale(path: Path) -> tuple[Image.Image, bool]:
128
  # valid dataset (dcmread force=True handles it).
129
  try:
130
  return _dicom_to_pil(path).convert("L"), True
131
- except Exception:
132
- pass # fall through to PIL so the error names the real problem
 
 
 
 
 
 
 
 
133
  return Image.open(path).convert("L"), False
134
 
135
 
 
128
  # valid dataset (dcmread force=True handles it).
129
  try:
130
  return _dicom_to_pil(path).convert("L"), True
131
+ except Exception as dicom_exc:
132
+ try:
133
+ return Image.open(path).convert("L"), False
134
+ except Exception as pil_exc:
135
+ with path.open("rb") as fh:
136
+ head = fh.read(16)
137
+ raise ValueError(
138
+ f"unreadable study {path.name}: size={path.stat().st_size} "
139
+ f"head={head.hex()} dicom_error={dicom_exc!r} pil_error={pil_exc!r}"
140
+ ) from pil_exc
141
  return Image.open(path).convert("L"), False
142
 
143