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

Generate more informative error message if a src_indices containing slicing operators was incorrectly set #1988

Conversation

hschilling
Copy link
Member

Summary

If the src_indices uses a slicing operator like a colon or ellipsis, and the user makes an error with the src_indices such that an exception occurs, the user only gets a very unhelpful error message like this:

IndexError: index 4 is out of bounds for axis 0 with size 4

A better error message needs to be generated so the user has some hint as to where the problem is.

This PR does that and also includes a test for it.

Related Issues

Backwards incompatibilities

None

New Dependencies

None

src_inds = _slice_indices(src_inds, np.prod(parent_src_shape),
parent_src_shape)
except IndexError as err:
raise IndexError(f"In component {self.msginfo}: \nError '{err}'\n in "
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the "In component" part of this message. All of our other error messages just start with {self.msg_info}:, which gives the class and name of the system/component.. This message would be inconsistent with that common format.

p.setup()

self.assertTrue(str(e.exception).startswith("In component 'row4_comp'"))
self.assertTrue(str(e.exception).endswith("with src_indices='(4, Ellipsis)'"))
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like you should just check the entire message, which would also test the value of {oldprom}...

@swryan swryan merged commit a5c532c into OpenMDAO:master Apr 5, 2021
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.

Need better error message when connections with src_indices includes colon or ellipsis operator
3 participants