Skip to content

Commit 1198bd9

Browse files
committed
Fix: derive supported formats dynamically in ImageWriter error message
1 parent a517854 commit 1198bd9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

monai/data/image_writer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence:
116116
except Exception: # other writer init errors indicating it exists
117117
avail_writers.append(_writer)
118118
if not avail_writers and error_if_not_found:
119-
raise OptionalImportError(f"No ImageWriter backend found for {fmt}. Please install a suitable package: 'nibabel' (for .nii/.nii.gz), 'itk' (for .nrrd/.mha), or 'Pillow' (for .png/.jpg).")
119+
_supported = ", ".join(sorted(SUPPORTED_WRITERS.keys()))
120+
raise OptionalImportError(
121+
f"No ImageWriter backend found for {fmt}. "
122+
f"Supported formats: {_supported}. "
123+
f"Please install a suitable package such as 'nibabel', 'itk', or 'Pillow'."
124+
)
120125
writer_tuple = ensure_tuple(avail_writers)
121126
SUPPORTED_WRITERS[fmt] = writer_tuple
122127
return writer_tuple

0 commit comments

Comments
 (0)