On Mon, Apr 25, 2022 at 1:55 PM Kenneth Porter via Boost <boost@lists.boost.org> wrote:
I don't see any information on where in the source string the parse error happened so I have to set a breakpoint in my tag_invoke functions to figure out where the syntax errors lie.
You have two potentially throwing lines: boost::json::value jv = boost::json::parse(contents); and axes = boost::json::value_to<std::vector<AxisProperties> If your exception is coming from the call to parse() and you want to know where in the string you are, then you need to change your code to create an instance of json::parser and call parser::write or parser::write_some to feed in the input. These functions return the number of characters consumed, which will be less than the amount passed in if an error occurs. In this case, the number of characters parsed successfully can be used to calculate an offset into the input buffer to determine where the syntax error happened. If your exception is coming from the call to value_to<>(), things are not so simple. The original JSON string is no longer available, and information about which json::value came from what part of the string is not stored (that would slow down the library and take up unnecessary memory). The best you can do in this case is to set up BOOST_THROW_EXCEPTION to get a breakpoint at the moment an exception is thrown, and then use a debugger to inspect the state of the program. You can also attach source file and line number information to exceptions when they are thrown (the library already does this). Boost.JSON throws all exceptions from these functions; alternatively, you could set a breakpoint in each of them to inspect the state of the program when an error is encountered: <https://github.com/boostorg/json/blob/83c364afaf31b58cfe8b97ab159c406c508f47c9/include/boost/json/detail/impl/except.ipp> Thanks