Skip to content

[BUG] Bare "except:" in OsipiBase.osipi_fit_full_volume() silently swallows all errors and catches SystemExit #144

@Devguru-codes

Description

@Devguru-codes

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In src/wrappers/OsipiBase.py at line 377, there is a bare except: block inside osipi_fit_full_volume().

Since it does not specify Exception, it catches built-in exceptions like KeyboardInterrupt and SystemExit, making it impossible for the user to Ctrl+C or gracefully terminate a long-running volume fit. Additionally, whenever any error occurs (such as a ValueError due to a data shape mismatch), it silently prints "Full volume fitting not supported for this algorithm" and returns False without showing the actual traceback or error message. This makes debugging impossible.

Screenshots [optional]

No response

Steps To Reproduce

Minimal Python script to simulate the issue on the main branch. It deliberately provides an unmatching 3D data shape (bad_data) to trigger a ValueError. Be aware it will silently fail without indicating the actual error.

import numpy as np
from src.wrappers.OsipiBase import OsipiBase

# Create a mock 3D data volume and b-values
bvalues = np.array([0, 10, 20, 50, 100, 200, 500, 800])
# The last dimension is explicitly wrong (5 instead of 8)
bad_data = np.random.rand(3, 3, 5) 

print("Starting osipi_fit_full_volume() with mismatched data shape...")

fit = OsipiBase(algorithm="PV_MUMC_biexp", bvalues=bvalues)
result = fit.osipi_fit_full_volume(bad_data, bvalues)

print(f"\nResult: {result}")
if result is False:
    print("FAILED: osipi_fit_full_volume returned False silently, obscuring the ValueError!")

Output on main branch:

Starting osipi_fit_full_volume() with mismatched data shape...
Full volume fitting not supported for this algorithm

Result: False
FAILED: osipi_fit_full_volume returned False silently, obscuring the ValueError!

Expected behavior

  1. Users should be able to interrupt the process using Ctrl+C.
  2. Normal errors (like numpy shape mismatch or algorithmic bugs) should either raise a loud exception, or print the appropriate error type and message for debugging.

Suggested Fix

Replace the bare except: with except Exception as e: and include diagnostic logging in the fallback block:

        except Exception as e:
            # Check if the problem is that full volume fitting is simply not supported in the standardized implementation
            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 False

Are you working on this?

Yes. I am making a pr to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions