Skip to content

Fix: add package install hint to ImageWriter backend error message#8795

Open
Talhax55z wants to merge 3 commits intoProject-MONAI:devfrom
Talhax55z:my-first-fix
Open

Fix: add package install hint to ImageWriter backend error message#8795
Talhax55z wants to merge 3 commits intoProject-MONAI:devfrom
Talhax55z:my-first-fix

Conversation

@Talhax55z
Copy link
Copy Markdown

Fixes #7980

Description

When no suitable ImageWriter backend is found, the error message previously
only said "No ImageWriter backend found for {fmt}." which gives the user
no actionable information.

This change adds a clear install hint to the error message, telling the
user which package to install depending on their file format.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 533af789-459e-4f99-9b0d-979ced551a97

📥 Commits

Reviewing files that changed from the base of the PR and between 1198bd9 and 4029c61.

📒 Files selected for processing (1)
  • monai/data/image_writer.py
✅ Files skipped from review due to trivial changes (1)
  • monai/data/image_writer.py

📝 Walkthrough

Walkthrough

The resolve_writer() failure path in monai/data/image_writer.py now raises an OptionalImportError with an expanded message when no suitable ImageWriter backend is found and error_if_not_found=True. The message builds a comma-separated list of supported format keys from SUPPORTED_WRITERS (excluding "*") and suggests likely packages to install (e.g., nibabel, itk, Pillow). No public APIs or function signatures were changed; the modification is limited to the error message content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and specifically describes the main change: adding package install hints to ImageWriter backend error messages.
Description check ✅ Passed Description includes all required template sections: issue reference (#7980), clear explanation of the problem and solution, and checkbox selections indicating non-breaking change.
Linked Issues check ✅ Passed Code changes directly address #7980 by appending install package hints to error messages when no ImageWriter backend is found, providing actionable guidance.
Out of Scope Changes check ✅ Passed Changes are limited to error message improvement in resolve_writer() function, remaining within scope of #7980 objective with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
monai/data/image_writer.py (1)

119-119: Avoid static backend hints that can drift from actual writer registration.

Line 119 hard-codes extension/package guidance and can go stale (for example, registered formats like jpeg, bmp, tiff, and tif are not represented). Prefer deriving the hint from a single shared mapping or from registered writers so messaging stays accurate as init() evolves.

As per coding guidelines, "Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@monai/data/image_writer.py` at line 119, The raise in ImageWriter where
OptionalImportError is constructed uses a hard-coded hint string for
packages/extensions; change it to compute the hint dynamically from the shared
writer registry used by init() (e.g., derive supported extensions/packages from
the module-level writer registry or mapping such as the writers registry used by
ImageWriter/init/_writer_registry) and include that generated list in the error
message instead of the static "'nibabel'...'Pillow'" text; update the
OptionalImportError message construction to enumerate current registered formats
(fmt alternatives) and, if you have a mapping of format→package names, build the
suggested package list from that mapping so the message stays accurate as init()
registers new writers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@monai/data/image_writer.py`:
- Line 119: The raise in ImageWriter where OptionalImportError is constructed
uses a hard-coded hint string for packages/extensions; change it to compute the
hint dynamically from the shared writer registry used by init() (e.g., derive
supported extensions/packages from the module-level writer registry or mapping
such as the writers registry used by ImageWriter/init/_writer_registry) and
include that generated list in the error message instead of the static
"'nibabel'...'Pillow'" text; update the OptionalImportError message construction
to enumerate current registered formats (fmt alternatives) and, if you have a
mapping of format→package names, build the suggested package list from that
mapping so the message stays accurate as init() registers new writers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a01a476f-c35f-4d1d-a7a7-b666bd83f1ed

📥 Commits

Reviewing files that changed from the base of the PR and between b887eae and a517854.

📒 Files selected for processing (1)
  • monai/data/image_writer.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@monai/data/image_writer.py`:
- Around line 119-124: The supported-format message currently includes the
wildcard key EXT_WILDCARD ("*") from SUPPORTED_WRITERS, which confuses users;
before building _supported, filter SUPPORTED_WRITERS.keys() to exclude
EXT_WILDCARD (or any literal "*") and then join/sort the remaining keys so the
OptionalImportError message lists only real formats—update the code around the
OptionalImportError raise (where _supported is computed) to perform this
filtering.
🪄 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: 4f4813af-57cc-4a0d-a92e-4db735bdfdd6

📥 Commits

Reviewing files that changed from the base of the PR and between a517854 and 1198bd9.

📒 Files selected for processing (1)
  • monai/data/image_writer.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print what package should be installed when suitable writer is missing

1 participant