Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message if adding neurodata types of the wrong types as property values #638

Merged
merged 18 commits into from
Dec 12, 2024

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Nov 25, 2024

Motivation

Throw more precise error message if trying to set a Neurodata type which is incorrect type

How to test the behavior?

Before

not_a_device = types.core.OpticalChannel('description', 'test_channel');
electrodeGroup = types.core.ElectrodeGroup(...
    'description', 'test_group', ...
    'device', not_a_device); %#ok<NASGU>
        
Error using assert
Value of type `types.core.OpticalChannel` cannot be converted to type `types.core.Device`:
  value is not instance of type types.core.Device. Got type types.core.OpticalChannel instead

After

not_a_device = types.core.OpticalChannel('description', 'test_channel');
electrodeGroup = types.core.ElectrodeGroup(...
    'description', 'test_group', ...
    'device', not_a_device); %#ok<NASGU>
        
Error using assert
Expected value for `device` to be of type `types.core.Device`. Instead it was `types.core.OpticalChannel`

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.24%. Comparing base (9b73801) to head (153fa2d).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
+matnwb/+utility/isNeurodataTypeClassName.m 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #638   +/-   ##
=======================================
  Coverage   95.23%   95.24%           
=======================================
  Files         115      117    +2     
  Lines        4873     4901   +28     
=======================================
+ Hits         4641     4668   +27     
- Misses        232      233    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ehennestad ehennestad marked this pull request as ready for review December 12, 2024 09:03
Comment on lines 12 to 14
tf = false;
if startsWith(typeName, 'types.') && ~startsWith(typeName, 'types.untyped')
tf = true;
Copy link
Contributor

@bendichter bendichter Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tf = false;
if startsWith(typeName, 'types.') && ~startsWith(typeName, 'types.untyped')
tf = true;
tf = startsWith(typeName, 'types.') && ~startsWith(typeName, 'types.untyped');

Copy link
Collaborator Author

@ehennestad ehennestad Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to check that the provided string is a class which inherits from types.untyped.MetaClass.

That previous implementation would return true for any string starting with typed.<something>

@bendichter
Copy link
Contributor

lgtm!

@ehennestad ehennestad merged commit bb9acbf into master Dec 12, 2024
7 checks passed
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