Skip to content

Commit e05dac4

Browse files
committed
YAML: Try to recover from more types of errors
1 parent ce472dd commit e05dac4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

common/YAML.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include "YAML.h"
55

6-
#include "Assertions.h"
7-
86
#if RYML_VERSION_MAJOR > 0 || RYML_VERSION_MINOR >= 11
97
#include "c4/yml/error.def.hpp" // for ryml::err_basic_format etc
108
#endif
@@ -28,15 +26,16 @@ std::optional<ryml::Tree> ParseYAMLFromString(ryml::csubstr yaml, ryml::csubstr
2826
callbacks.set_user_data(static_cast<void*>(&context));
2927

3028
callbacks.set_error_basic([](ryml::csubstr msg, const ryml::ErrorDataBasic& errdata, void* user_data) {
29+
RapidYAMLContext* context = static_cast<RapidYAMLContext*>(user_data);
30+
3131
std::string description;
3232
auto callback = [&description](ryml::csubstr string) {
3333
description.append(string.str, string.len);
3434
};
3535
ryml::err_basic_format(std::move(callback), msg, errdata);
3636

37-
// We might have already returned, so don't try to recover.
38-
pxFailRel(description.c_str());
39-
std::abort();
37+
Error::SetString(context->error, std::move(description));
38+
std::longjmp(context->env, 1);
4039
});
4140

4241
callbacks.set_error_parse([](ryml::csubstr msg, const ryml::ErrorDataParse& errdata, void* user_data) {
@@ -53,15 +52,16 @@ std::optional<ryml::Tree> ParseYAMLFromString(ryml::csubstr yaml, ryml::csubstr
5352
});
5453

5554
callbacks.set_error_visit([](ryml::csubstr msg, const ryml::ErrorDataVisit& errdata, void* user_data) {
55+
RapidYAMLContext* context = static_cast<RapidYAMLContext*>(user_data);
56+
5657
std::string description;
5758
auto callback = [&description](ryml::csubstr string) {
5859
description.append(string.str, string.len);
5960
};
6061
ryml::err_visit_format(std::move(callback), msg, errdata);
6162

62-
// We've probably already returned, so don't try to recover.
63-
pxFailRel(description.c_str());
64-
std::abort();
63+
Error::SetString(context->error, std::move(description));
64+
std::longjmp(context->env, 1);
6565
});
6666
#else
6767
callbacks.m_user_data = static_cast<void*>(&context);

0 commit comments

Comments
 (0)