Skip to content

fix: replace raise UserWarning with warnings.warn() in verify_report_format (Fixes #8927)#8928

Open
rtmalikian wants to merge 1 commit into
Project-MONAI:devfrom
rtmalikian:fix/issue-8927-raise-userwarning
Open

fix: replace raise UserWarning with warnings.warn() in verify_report_format (Fixes #8927)#8928
rtmalikian wants to merge 1 commit into
Project-MONAI:devfrom
rtmalikian:fix/issue-8927-raise-userwarning

Conversation

@rtmalikian

@rtmalikian rtmalikian commented Jun 19, 2026

Copy link
Copy Markdown

Fixes #8927

Problem

In monai/auto3dseg/utils.py line 287, the code uses raise UserWarning("list length in report_format is not 1"). This raises UserWarning as an exception, which crashes the program. Since UserWarning inherits from Warning → Exception, the raise works but terminates execution.

The function verify_report_format returns bool to indicate format validity — a warning is appropriate here, not a fatal exception. The warnings module is already imported in the file.

Solution

Replace raise UserWarning(...) with warnings.warn(..., stacklevel=2):

# Before (crashes):
raise UserWarning("list length in report_format is not 1")

# After (warns):
warnings.warn("list length in report_format is not 1", stacklevel=2)

Verification

Confirmed that:

  • raise UserWarning(...) crashes the program (raises as exception)
  • warnings.warn(...) correctly emits a UserWarning without crashing
  • The file passes syntax validation
  • warnings is already imported in the file

About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.

📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a


Disclosure: This code was developed with assistance from mimo-2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.

Changelog

Date Change Author
2026-06-18 Initial fix: replace raise UserWarning with warnings.warn() rtmalikian
2026-06-18 Added DCO sign-off to commit rtmalikian
2026-06-18 Updated PR documentation with changelog rtmalikian

Files Changed

  • monai/auto3dseg/utils.py — Changed raise UserWarning(...) to warnings.warn(...) in verify_report_format()

Verification

  • ✅ Function no longer crashes on invalid report format
  • ✅ Warning is emitted instead of raising exception
  • ✅ Return value (bool) still indicates format validity
  • ✅ DCO sign-off present on all commits

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

In monai/auto3dseg/utils.py, the verify_report_format function no longer raises UserWarning when a nested report_format list length is not exactly 1. It now calls warnings.warn(..., stacklevel=2) instead, turning a fatal exception into a non-fatal runtime warning.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing raise UserWarning with warnings.warn() in the verify_report_format function.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description comprehensively covers the problem, solution, verification, and includes detailed changelog with DCO sign-off confirmation.

✏️ 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.

…rmat

In monai/auto3dseg/utils.py line 287,  was used
which raises the warning as an exception, crashing the program. The intent
was to emit a warning since the function returns bool to indicate format
validity.

Replaced with  which correctly emits a
UserWarning without crashing.

Fixes Project-MONAI#8927

Signed-off-by: Raphael Malikian <rtmalikian@gmail.com>
@rtmalikian rtmalikian force-pushed the fix/issue-8927-raise-userwarning branch from a5dd19e to 9315e04 Compare June 19, 2026 05:56
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.

fix: should be in verify_report_format

1 participant