Better diagnostic for value_to errors on described structures
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start at boost/json/detail/value_to.hpp around the reported line and reproduce the described C++ example with the missing currency member. Trace how value_to reports the unknown name and determine how the nested JSON location can be retained. Done means the exception diagnostic includes the path to the missing member, with coverage for the described-structure conversion.
Written by the indexing model from the issue text.
Description
Given the following use case that comes from the documentation:
#include <iostream>
#include <string>
#include <boost/json/src.hpp>
#include <boost/describe.hpp>
#include <boost/exception/diagnostic_information.hpp>
struct money
{
std::string currency;
double value;
};
BOOST_DESCRIBE_STRUCT(money, (), (currency, value))
struct test
{
double pi;
bool happy;
money object;
};
BOOST_DESCRIBE_STRUCT(test, (), (pi, happy, object))
int main()
{
boost::json::value jv = {
{ "pi", 3.141 },
{ "happy", true },
{"object", {
//{ "currency", "USD" },
{ "value", 42.99 }
}}
};
try {
test res = boost::json::value_to<test>(jv);
}
catch (std::exception const& ex) {
std::cerr << boost::diagnostic_information(ex, true) << std::endl;
}
return 0;
}
The missing currency member gives the following exception:
Dynamic exception type: boost::detail::with_throw_location<boost::system::system_error>
std::exception::what: unknown name [boost.json:39 at /nobackup/lid00lima21/debionne/miniconda3/envs/lima2/include/boost/json/detail/value_to.hpp:371 in function 'operator()']
It would be interesting to have an information where the exception occurred in the json value during value_to conversion. Ideally something like errinfo_json_path="object.concurreny".
- Dominant language
- C++
- Stars
- 478
- Forks
- 110
- Avg merge
- 8d 12h
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/json
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
sanitizer warning Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Similar issues
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 88/100
QuantStack/git2cpp#187 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
mlcommons/mobile_app_open#1182 ·
-
Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/winget-cli#6547 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·