fix: improve error message when no ImageWriter backend found#8853
fix: improve error message when no ImageWriter backend found#8853vikasreddy11 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughUpdate in monai/data/image_writer.py: Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
monai/data/image_writer.py (1)
119-119: ⚡ Quick winAdd tests for the new error messaging path.
Please add/extend unit tests for
resolve_writer(..., error_if_not_found=True)to verify message content for at least one PIL format and one non-PIL format.As per coding guidelines, "Ensure new or modified definitions will be covered by existing or new unit tests."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@monai/data/image_writer.py` at line 119, Add unit tests that call resolve_writer(fmt, error_if_not_found=True) and assert it raises OptionalImportError with the expected message content: for a PIL-backed format (e.g., "PNG") assert the exception message includes the format name and the pillow install hint ("Please install pillow (`pip install pillow`)"), and for a non-PIL format (pick another unsupported fmt) assert the message includes the format name and the generic "No ImageWriter backend found for {fmt}" text; use the OptionalImportError class from image_writer.py and the resolve_writer symbol to locate the behavior to test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@monai/data/image_writer.py`:
- Line 119: The current OptionalImportError raised in image_writer.py hardcodes
a Pillow install hint for all formats; update the raise in the ImageWriter
selection path (where fmt and candidate writers are known) to produce a generic
"No ImageWriter backend found for {fmt}" message and then append
format-appropriate installation hints: e.g., if fmt corresponds to medical
volumes (nifti/nii/nii.gz or any fmt present in candidate_writers that map to
nibabel/itk) append "install nibabel or itk (`pip install nibabel itk`)", if fmt
is an image extension (jpeg/png/tiff or candidates that would use PILLOW) append
"install pillow (`pip install pillow`)", otherwise only return the generic
message; implement this conditional composition where the original raise occurs
(reference variable fmt and candidate_writers/ImageWriter selection logic) so
the error guidance is accurate per format.
---
Nitpick comments:
In `@monai/data/image_writer.py`:
- Line 119: Add unit tests that call resolve_writer(fmt,
error_if_not_found=True) and assert it raises OptionalImportError with the
expected message content: for a PIL-backed format (e.g., "PNG") assert the
exception message includes the format name and the pillow install hint ("Please
install pillow (`pip install pillow`)"), and for a non-PIL format (pick another
unsupported fmt) assert the message includes the format name and the generic "No
ImageWriter backend found for {fmt}" text; use the OptionalImportError class
from image_writer.py and the resolve_writer symbol to locate the behavior to
test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 47d0b132-e4c1-482d-a4eb-168b0b821093
📒 Files selected for processing (1)
monai/data/image_writer.py
Fixes # .
Description
Improved the error message when no ImageWriter backend is found to suggest
installing pillow
Before:
No ImageWriter backend found for png.After:
No ImageWriter backend found for png. Please install pillow (pip install pillow)Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.