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 of ascii data plugin while loading file #2755
Improve error message of ascii data plugin while loading file #2755
Conversation
b534a38
to
f3d7b48
Compare
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.
Except for this one point I had, this looks good. Thank you!
source/utilities.cc
Outdated
} | ||
else | ||
{ | ||
AssertThrow(field_index == (components + dim) * data_table.n_elements(), |
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.
This does not cover the case where you have a number of valid data points that's exactly the same as the POINTS value, and then a line that contains NaN.
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.
In addition, I find this logic a bit difficult to follow, so if you don't find a different way to write this, maybe you can add a comment that explains what happens in each case.
f3d7b48
to
2ce9260
Compare
I simplified the logic and improved the error message. Is this more clear? This should also cover the corner case you mentioned above. We now enforce the loop to read until the end of the file, otherwise it will throw an exception. |
source/utilities.cc
Outdated
|
||
AssertThrow(field_index == (components + dim) * data_table.n_elements(), | ||
ExcMessage (std::string("Number of read in points does not match number of expected points. File corrupted?"))); | ||
ExcMessage (std::string("While reading the data file '" + filename + "' the ascii data " |
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.
I think @jdannberg wants this assert() condition (which appears in the output) to be easier to understand (right?). Maybe we can do
ExcMessage (std::string("While reading the data file '" + filename + "' the ascii data " | |
const n_total_values = (components + dim) * data_table.n_elements(); | |
AssertThrow(field_index == n_total_values, |
and ... expected number of floating point values based on the dimension, the number of components, and the number of lines given by POINTS in the header of the file
.
source/utilities.cc
Outdated
@@ -1643,9 +1643,17 @@ namespace aspect | |||
} | |||
while (in >> temp_data); | |||
|
|||
AssertThrow(in.eof(), | |||
ExcMessage (std::string("While reading the data file '" + filename + "' the ascii data " |
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.
no need for the explicit conversion to std::string
. The addition of "..." + std::string
already does that.
2ce9260
to
85c2e69
Compare
Is this better? I renamed the variables to make the condition easier to understand. |
Looks good to me! |
…rong_entry_detection Improve error message of ascii data plugin while loading file
Fix #2753.