biojppm / rapidyaml

Rapid YAML - a library to parse and emit YAML, and do it fast.
MIT License
583 stars 100 forks source link

Request: Add more context to error traces #399

Open mcandre opened 10 months ago

mcandre commented 10 months ago

rapidyaml often reports check failed: (ch != NONE) when attempting to traverse YAML data that omits expected keys.

In large applications, most users will be confused by this message, unable to take action to correct the mistake.

Can we please present more specific error messages. For example, indicate the name of the YAML key that the application was attempting to lookup.

emmett2020 commented 10 months ago

Thats what I meet either. I make a wrapper for the lower level API usages. Its not easy and costs lots of time. Maybe a more detailed error trace messages should be added by ryml.

biojppm commented 7 months ago

I agree that the error messages could be improved. I am revisiting this in the context of #389 and I will devise a better solution.

biojppm commented 7 months ago

Actually this fix missed the boat on #389.

I'm thinking of adding a second error handler for node visitation:

// existing error handler: tuned for parsing
using pfn_error = void (*) (const char* msg, size_t msg_len, Location location, void *user_data);

// to be added: tuned for visiting
using pfn_error_visit = void (*) (const char* msg, size_t msg_len, Tree const& tree, size_t id, void *user_data);

But this involves a thorough look at the existing calls, so it will have to wait for ongoing work to be merged in (specifically #414 which is giant).