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

Record parse failure reason and location #252

Merged
merged 1 commit into from
Aug 3, 2024

Conversation

LeszekSwirski
Copy link
Collaborator

In parse_number_string, if there is a parse error, report the specific
error as one of the values in a new parse_error enum, and update
lastmatch to match the error location. This allows users of the library
to print more helpful error messages for invalid inputs.

@LeszekSwirski
Copy link
Collaborator Author

Happy to discuss alternatives to this, this was just the simplest approach that came to mind and I figured it's easier to make a code-based suggestion than an abstract one.

@lemire
Copy link
Member

lemire commented Jul 22, 2024

I figured it's easier to make a code-based suggestion than an abstract one.

Yep.

@lemire
Copy link
Member

lemire commented Jul 22, 2024

@LeszekSwirski Can you sync your fork with our main branch. I had to do a forced update to fix problems I created earlier today.

Your PR seems quite reasonable and maybe we want to include it in a release very soon.

@LeszekSwirski
Copy link
Collaborator Author

Sure, done.

@lemire
Copy link
Member

lemire commented Jul 22, 2024

I will push a patch release immediately because I want your fix from an earlier PR. Meanwhile let us turn this PR into at least a minor release.

@LeszekSwirski
Copy link
Collaborator Author

Sounds reasonable, it's an observable API change if anyone checks pnr.lastmatch instead of pnr.valid. I could make it backwards compatible by adding a new const UC* error_location if you wanted? No strong opinion from my end.

@lemire
Copy link
Member

lemire commented Jul 22, 2024

@deadalnix Would you have a look? I think that this PR is a nice step up.

@lemire
Copy link
Member

lemire commented Jul 22, 2024

@LeszekSwirski I am not 100% sure that we have users of this part of our API. But it is more than a patch for sure.

@deadalnix
Copy link
Contributor

The obvious thing that jump to my eyes here is the lack of tests :)

The feature looks good, the implementation fairly uncontroversial considering the conditions are already checked for, so for me, as long as there is a good test, I think it should go it.

@LeszekSwirski
Copy link
Collaborator Author

Fair comment 😄 I'll add some tests tomorrow.

@lemire
Copy link
Member

lemire commented Jul 23, 2024

@LeszekSwirski Thanks for adding tests.

Comment on lines 25 to 27
const std::string input = "inf"; // not valid in JSON
double result;
fast_float::parse_options options{ fast_float::chars_format::json };
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
if(answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; }
auto answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result, options);
if (answer.ec == std::errc()) {
std::cerr << "should have failed\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
Copy link
Contributor

Choose a reason for hiding this comment

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

You have indentation problems here.

@lemire what do you think about adding a clang-format config file so we can avoid this type of review cycles?

Copy link
Member

Choose a reason for hiding this comment

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

@deadalnix Please review #257

I don't think we want to consider formatting mistakes as blocking for a PR. We can reformat later.

@lemire
Copy link
Member

lemire commented Jul 23, 2024

This PR looks good to me. I am inviting further review.

This would be at least a minor release.

@LeszekSwirski
Copy link
Collaborator Author

Sorry, the formatting was a bad push, it wasn't intended for review

In parse_number_string, if there is a parse error, report the specific
error as one of the values in a new parse_error enum, and update
lastmatch to match the error location. This allows users of the library
to print more helpful error messages for invalid inputs.
@LeszekSwirski
Copy link
Collaborator Author

@deadalnix ok now the formatting is fixed (just a "format on save" mess up)

@lemire
Copy link
Member

lemire commented Jul 23, 2024

ok now the formatting is fixed (just a "format on save" mess up

Thankfully, we have tools to automatically format. Although, for this project, we don't have a standard yet. If you are interested, I have a PR outstanding that would prescribe a given style:

#257

@lemire
Copy link
Member

lemire commented Jul 23, 2024

The tests pass. We will merge this PR unless someone objects in the near future.

@lemire
Copy link
Member

lemire commented Aug 3, 2024

Merging. This will be part of the next release.

@lemire lemire merged commit 0e7a10a into fastfloat:main Aug 3, 2024
38 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.

3 participants