Replace BaseException with Exception across codebase#8859
Conversation
) Catching BaseException inadvertently suppresses KeyboardInterrupt, SystemExit, and GeneratorExit, which should nearly always propagate. All 17 occurrences across monai/ and tests/ are replaced with Exception, which is the appropriate base class for catchable errors. Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
📝 WalkthroughWalkthroughThis PR systematically narrows exception handling from Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
…@gmail.com> I, Oleksandr Yizchak Sanin <alexaaander.sanin@gmail.com>, hereby add my Signed-off-by to this commit: e3a2bb2 Signed-off-by: Oleksandr Yizchak Sanin <alexaaander.sanin@gmail.com>
ericspod
left a comment
There was a problem hiding this comment.
Hi @AlexanderSanin thanks for this update, it looks good to me. I went through the changes and don't see anywhere we needed to catch subtypes of BaseException such as KeyboardInterrupt.
Summary
Fixes #7401
except BaseExceptionwithexcept Exceptionacross 13 files inmonai/andtests/BaseExceptioninadvertently suppressesKeyboardInterrupt,SystemExit, andGeneratorExit, which should nearly always propagateExceptionis the appropriate base class for catchable errors in all these contextsFiles changed
monai/__init__.pymonai/config/deviceconfig.pymonai/utils/tf32.pymonai/inferers/inferer.pymonai/data/__init__.pymonai/apps/auto3dseg/utils.pymonai/apps/auto3dseg/ensemble_builder.pymonai/apps/auto3dseg/data_analyzer.pymonai/apps/detection/metrics/coco.pymonai/apps/nnunet/nnunetv2_runner.pytests/test_utils.pytests/networks/nets/test_resnet.pytests/apps/detection/networks/test_retinanet.pyTest plan
KeyboardInterrupt(Ctrl+C) is no longer silently swallowed during long-running operationsSigned-off-by: Oleksandr Sanin alexaaander.sanin@gmail.com