Skip to content

Fix: Replace bare and broad exceptions with NeuroBlueprintError#699

Open
Kayd-06 wants to merge 1 commit intoneuroinformatics-unit:mainfrom
Kayd-06:fix-bare-exceptions
Open

Fix: Replace bare and broad exceptions with NeuroBlueprintError#699
Kayd-06 wants to merge 1 commit intoneuroinformatics-unit:mainfrom
Kayd-06:fix-bare-exceptions

Conversation

@Kayd-06
Copy link

@Kayd-06 Kayd-06 commented Feb 27, 2026

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

Bare except: blocks and overly broad except Exception: catches can intercept critical system-level exceptions like KeyboardInterrupt and SystemExit, as well as mask unexpected application bugs (like AttributeError or IndexError). This makes debugging extremely difficult and hides actual bugs.

What does this PR do?

  • Replaces a bare except: block and an except Exception: block in datashuttle/utils/validation.py with except NeuroBlueprintError:.
  • Adds an explicit check in datashuttle/utils/utils.py to raise a NeuroBlueprintError when regex parsing of a BIDS value comes up empty, instead of implicitly causing an IndexError. This allows the validation logic to safely and explicitly catch the expected error.

References

N/A

How has this PR been tested?

The test suite was run locally using pytest. The test_validation_unit.py module passed successfully, confirming the previous behavior of the validation functions remains intact while safely catching the intended exceptions.

Is this a breaking change?

No.

Does this PR require an update to the documentation?

No.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@JoeZiminski
Copy link
Member

Thanks @Kayd-06, this looks good. but will hold off reviewing and merging until after the next big release, in case it has some unintended side-effects. Thanks!

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.

2 participants