boostorg / boostorg/json

Better diagnostic for value_to errors on described structures

Open
#1,069 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
479
Forks
110
Avg merge
10d 3h
Merged PRs (30d)
5

Description

Given the following use case that comes from the documentation:

```c++
#include
#include

#include
#include
#include

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(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:

```bash
Dynamic exception type: boost::detail::with_throw_location
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"`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.