-
Notifications
You must be signed in to change notification settings - Fork 128
Handle out of bounds error in nthIterval of FilteredTimeSeriesProperty #39238
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one change for the test, otherwise works as intendended. output I go from running the script:
LoadMuonNexus started
Geometry cache is not available
Creating cache in C:\Users\bya67386\AppData\Roaming\mantidproject\mantid\instrument\geometryCache\HIFI7a5093e08ddd5090d58abd7fc3aab4d5cc1547e4.vtp
Sample Log "Field_Hall_Z" contains invalid values, click "Show Sample Logs" for details.
Sample Log "Field_Hall_Z" and 0 other contain invalid values, click "Show Sample Logs" for details.
Log "running" has 36 entries removed due to duplicated time.
LoadMuonNexus successful, Duration 3.30 seconds
RuntimeError: nthInterval(): FilteredTimeSeriesProperty 'Field_Main' interval 109 does not exist
File "<string>", line 6, in <module>
// Throw exception if out of bounds | ||
if (n >= static_cast<int>(this->m_filterIntervals.size())) { | ||
const std::string error("nthInterval(): FilteredTimeSeriesProperty '" + this->name() + "' interval " + | ||
std::to_string(n) + " does not exist"); | ||
g_log.debug(error); | ||
throw std::runtime_error(error); | ||
} else { | ||
deltaT = this->m_filterIntervals[std::size_t(n)]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do this with at()
, supposed to be a safe way to access vectors, although it still throws an exception?
https://en.cppreference.com/w/cpp/container/array/at
Just letting you know about it, the code is fine as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think we want the custom error message in this case, in keeping with other error handling within the function.
702a794
to
384af75
Compare
#39238) * throw error if out of bounds in nthIterval * add release note * update nthInterval test * satisfy cppcheck - remove std::move to allow for nrvo * cast size_t to int to resolve compiler warnings * respond to review comments
Description of work
Reported by a user, possible to provide an
n
argument tonthTime
ornthInterval
method of aFilteredTimeSeriesProperty
and get an out of bounds error.This PR adds bounds checking.
To test:
Ensure instrument is
HIFI
and data archive access is available.Ensure error is handled when running the following script:
Reviewer
Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.
Code Review
Functional Tests
Does everything look good? Mark the review as Approve. A member of
@mantidproject/gatekeepers
will take care of it.Gatekeeper
If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.