Skip to content

fix: add runtime guards in BlockUnit and fix SubInfo bare except#19

Open
HugoFara wants to merge 3 commits intoTaskBeacon:mainfrom
HugoFara:fix/blockunit-subinfo-guards
Open

fix: add runtime guards in BlockUnit and fix SubInfo bare except#19
HugoFara wants to merge 3 commits intoTaskBeacon:mainfrom
HugoFara:fix/blockunit-subinfo-guards

Conversation

@HugoFara
Copy link
Contributor

Hi @zh1peng , this PR fixes a few bugs I found in the app.

  • BlockUnit.run_trial(): Raise RuntimeError when run_trial() is called before generate_conditions() (previously crashed with opaque message)
  • BlockUnit.run_trial(): raise TypeError when the trial function returns a non-dict (previously crashed with AttributeError: 'NoneType' object has no attribute 'update')
  • BlockUnit.logging_block_info(): fix .count() call on numpy array (use np.sum() instead) and guard against conditions=None
  • SubInfo.validate(): replace bare except: with except Exception: so KeyboardInterrupt propagates (Ctrl+C was being
    swallowed)

I also included a few tests to check for regressions:

  • tests/test_BlockUnit.py — verifies both guards produce clear error messages
  • tests/test_SubInfo.py — verifies cancel path and KeyboardInterrupt propagation

- Raise RuntimeError when run_trial() is called before generate_conditions()
- Raise TypeError when trial function returns non-dict
- Fix logging_block_info() calling .count() on numpy array
- Replace bare except: with except Exception: in SubInfo.validate()
- Add test_BlockUnit.py and test_SubInfo.py covering these paths
CI environment does not have numpy installed. Use a plain list instead
of np.array() since enumerate() works on both.
The CI smoke job only installs pyyaml — numpy and psychopy are not
available. Use skipUnless with a try-import guard instead of stubbing
sys.modules, matching the existing pattern in test_cli_root.py.
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.

1 participant