@@ -24,13 +24,52 @@ namespace sdk
2424namespace configuration
2525{
2626
27- // Custom ryml error callback that throws instead of calling abort().
28- // This ensures the try-catch in ParseDocument works regardless of how
29- // ryml was compiled (with or without RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS).
30- void RymlDocument::OnError (const char *msg,
31- size_t msg_len,
32- ryml::Location location,
33- void * /* user_data*/ )
27+ #if RYML_VERSION_MINOR >= 11
28+ [[noreturn]] static void OnErrorBasic (c4::csubstr msg,
29+ const ryml::ErrorDataBasic &errdata,
30+ void * /* user_data*/ )
31+ {
32+ DocumentNodeLocation loc;
33+ loc.offset = errdata.location .offset ;
34+ loc.line = errdata.location .line ;
35+ loc.col = errdata.location .col ;
36+ loc.filename = std::string (errdata.location .name .str , errdata.location .name .len );
37+
38+ throw InvalidSchemaException (loc, std::string (msg.str , msg.len ));
39+ }
40+
41+ [[noreturn]] static void OnErrorParse (c4::csubstr msg,
42+ const ryml::ErrorDataParse &errdata,
43+ void * /* user_data*/ )
44+ {
45+ DocumentNodeLocation loc;
46+ loc.offset = errdata.ymlloc .offset ;
47+ loc.line = errdata.ymlloc .line ;
48+ loc.col = errdata.ymlloc .col ;
49+ loc.filename = std::string (errdata.ymlloc .name .str , errdata.ymlloc .name .len );
50+
51+ throw InvalidSchemaException (loc, std::string (msg.str , msg.len ));
52+ }
53+
54+ [[noreturn]] static void OnErrorVisit (c4::csubstr msg,
55+ const ryml::ErrorDataVisit &errdata,
56+ void * /* user_data*/ )
57+ {
58+ DocumentNodeLocation loc;
59+ loc.offset = errdata.cpploc .offset ;
60+ loc.line = errdata.cpploc .line ;
61+ loc.col = errdata.cpploc .col ;
62+ loc.filename = std::string (errdata.cpploc .name .str , errdata.cpploc .name .len );
63+
64+ // If rapidyaml fails internally, we declare the yaml document invalid.
65+ throw InvalidSchemaException (loc, std::string (msg.str , msg.len ));
66+ }
67+
68+ #else
69+ [[noreturn]] static void OnError (const char *msg,
70+ size_t msg_len,
71+ ryml::Location location,
72+ void * /* user_data*/ )
3473{
3574 DocumentNodeLocation loc;
3675 loc.offset = location.offset ;
@@ -40,11 +79,23 @@ void RymlDocument::OnError(const char *msg,
4079
4180 throw InvalidSchemaException (loc, std::string (msg, msg_len));
4281}
82+ #endif
4383
84+ // Custom ryml error callback that throws instead of calling abort().
85+ // This ensures the try-catch in ParseDocument works regardless of how
86+ // ryml was compiled (with or without RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS).
4487ryml::Callbacks RymlDocument::MakeCallbacks ()
4588{
4689 ryml::Callbacks cb = ryml::get_callbacks ();
47- cb.m_error = &RymlDocument::OnError;
90+ #if RYML_VERSION_MINOR >= 11
91+ // Starting with rapidyaml 0.11.0
92+ cb.m_error_basic = OnErrorBasic;
93+ cb.m_error_parse = OnErrorParse;
94+ cb.m_error_visit = OnErrorVisit;
95+ #else
96+ // Up to rapidyaml 0.10.0
97+ cb.m_error = OnError;
98+ #endif
4899 return cb;
49100}
50101
0 commit comments