fix: replace bare except with except Exception in osipi_fit_full_volume#145
Open
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Open
fix: replace bare except with except Exception in osipi_fit_full_volume#145Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Conversation
Replace bare 'except:' with 'except Exception as e:' in OsipiBase.osipi_fit_full_volume() (line 377). Before: bare except caught KeyboardInterrupt/SystemExit (cannot Ctrl+C) and silently swallowed all errors with no diagnostic output. After: only catches Exception subclasses, adds diagnostic print() showing error type and message for debuggability. No regressions: 1127 passed, 167 skipped, 22 xfailed, 6 xpassed.
Author
|
Branch: The Bug
# BEFORE (line 377):
except:
if not hasattr(self, "ivim_fit_full_volume"):
print("Full volume fitting not supported for this algorithm")
return FalseIssue Reproduction (BEFORE fix)from src.wrappers.OsipiBase import OsipiBase
import numpy as np
bvalues = np.array([0, 10, 20, 50, 100, 200, 500, 800])
# Test: Algorithm without full volume support
fit = OsipiBase(algorithm="PV_MUMC_biexp", bvalues=bvalues)
data = np.random.rand(2, 2, len(bvalues))
result = fit.osipi_fit_full_volume(data, bvalues)
# Result: False (returned silently — no error info!)
# Test: Wrong data shape
bad_data = np.random.rand(3, 3, 5) # last dim doesn't match bvalues
result2 = fit.osipi_fit_full_volume(bad_data, bvalues)
# Result: False (silently — was it shape mismatch? crash? unsupported?)Output (before fix): No distinction between "unsupported algorithm" vs "actual crash/error" — both silently return The Fix- except:
+ except Exception as e:
# Check if the problem is that full volume fitting is simply not supported
if not hasattr(self, "ivim_fit_full_volume"):
print("Full volume fitting not supported for this algorithm")
+ else:
+ print(f"Full volume fitting failed: {type(e).__name__}: {e}")
return FalseWhat it does:
Verification (AFTER fix)Output (after fix): Now users can distinguish between "unsupported" and "actual error" and can debug the failure. Sanity Check — Full Test Suite
Zero regressions. All existing tests pass identically. Environment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description:
Description
This PR fixes Issue #144 by replacing the bare
except:block inOsipiBase.osipi_fit_full_volume()withexcept Exception as e:.Changes Made
src/wrappers/OsipiBase.pyat line 377 to catchExceptioninstead of all base exceptions.print()statement that outputs the actual error type and message when full volume fitting fails.Why is this needed?
except:was catchingKeyboardInterruptandSystemExit. This prevented users from usingCtrl+Cto stop long-running volume fitting operations.ValueErrorfrom bad data shape or algorithm crashes) were silently swallowed, returningFalsewith the confusing message"Full volume fitting not supported for this algorithm". Now, actual errors print a helpful diagnostic message, while unsupported algorithms still returnFalsequietly with the correct unsupported message.Testing/Verification
pytest tests/IVIMmodels/unit_tests/test_ivim_fit.py). Verified 1127 passed, 167 skipped, 22 xfailed, 6 xpassed. No regressions.Ctrl+Ccan now cleanly interrupt the process.Resolves #144