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

array_index does not catch std::invalid_argument exception from std::stoull #3831

Closed
2 tasks
StarryVae opened this issue Nov 14, 2022 · 2 comments
Closed
2 tasks

Comments

@StarryVae
Copy link

Description

array_index does not catch std::invalid_argument exception from std::stoull, which means we need catch the exception in our code when using nlohmann json.

for example, for a json body json_body: {\"foo\":\"val\",\"bar\":\"val\",\"array\":[\"a1\",\"a2\"]}, if json pointer json_pointer was set incorrectly like /array/, when we call json_body.contains(json_pointer), it will throw std::invalid_argument exception.

Reproduction steps

for a json body json_body: {\"foo\":\"val\",\"bar\":\"val\",\"array\":[\"a1\",\"a2\"]}, if json pointer json_pointer was set incorrectly like /array/, when we call json_body.contains(json_pointer), it will throw std::invalid_argument exception.

Expected vs. actual results

Expected:
catch nlohmann::detail::exception is enough.

Actual:
just catch nlohmann::detail::exception is not enough, crush will happen due to std::invalid_argument exception.

Minimal code example

No response

Error messages

No response

Compiler and operating system

clang 7.0.1 ubuntu 18.04

Library version

3.10.5

Validation

@falbrechtskirchinger
Copy link
Contributor

falbrechtskirchinger commented Nov 14, 2022

This has been fixed (#3415).

v3.10.5

terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoull

v3.11.2

terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::out_of_range'
  what():  [json.exception.out_of_range.404] unresolved reference token ''

@StarryVae
Copy link
Author

This has been fixed (#3415).

v3.10.5

terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoull

v3.11.2

terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::out_of_range'
  what():  [json.exception.out_of_range.404] unresolved reference token ''

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants