-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error handling #411
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #411 +/- ##
==========================================
- Coverage 96.63% 96.62% -0.01%
==========================================
Files 22 22
Lines 8266 8391 +125
==========================================
+ Hits 7988 8108 +120
- Misses 278 283 +5 ☔ View full report in Codecov by Sentry. |
Tried your branch. Thanks for tackling this! One thing to note, you'll need to add some kind of void cast or
I had a small patch against an older commit that fixed all of them, but it probably doesn't merge quite cleanly any more: diff --git a/src/c4/yml/parse.cpp b/src/c4/yml/parse.cpp
index a0f0dad..fbfc88c 100644
--- a/src/c4/yml/parse.cpp
+++ b/src/c4/yml/parse.cpp
@@ -4532,6 +4532,7 @@ bool Parser::_filter_nl(substr r, size_t *C4_RESTRICT i, size_t *C4_RESTRICT pos
_RYML_CB_ASSERT(m_stack.m_callbacks, indentation != npos);
_RYML_CB_ASSERT(m_stack.m_callbacks, curr == '\n');
+ (void) curr;
_c4dbgfnl("found newline. sofar=[{}]~~~{}~~~", *pos, m_filter_arena.first(*pos));
size_t ii = *i;
diff --git a/src/c4/yml/parse.hpp b/src/c4/yml/parse.hpp
index 659edf7..9a4993a 100644
--- a/src/c4/yml/parse.hpp
+++ b/src/c4/yml/parse.hpp
@@ -388,9 +388,9 @@ private:
csubstr _consume_scalar();
void _move_scalar_from_top();
- inline NodeData* _append_val_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); return _append_val({nullptr, size_t(0)}); }
- inline NodeData* _append_key_val_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); return _append_key_val({nullptr, size_t(0)}); }
- inline void _store_scalar_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); _store_scalar({nullptr, size_t(0)}, false); }
+ inline NodeData* _append_val_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); (void) str; return _append_val({nullptr, size_t(0)}); }
+ inline NodeData* _append_key_val_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); (void) str; return _append_key_val({nullptr, size_t(0)}); }
+ inline void _store_scalar_null(const char *str) { _RYML_CB_ASSERT(m_stack.m_callbacks, str >= m_buf.begin() && str <= m_buf.end()); (void) str; _store_scalar({nullptr, size_t(0)}, false); }
void _set_indentation(size_t behind);
void _save_indentation(size_t behind=0);
diff --git a/src/c4/yml/tree.cpp b/src/c4/yml/tree.cpp
index b381986..fd8153d 100644
--- a/src/c4/yml/tree.cpp
+++ b/src/c4/yml/tree.cpp
@@ -1826,6 +1826,8 @@ csubstr _transform_tag(Tree *t, csubstr tag, size_t node)
_RYML_CB_ASSERT(t->m_callbacks, t->arena().str == prev_arena);
size_t actual_size = t->resolve_tag(buf, tag, node);
_RYML_CB_ASSERT(t->m_callbacks, actual_size <= required_size);
+ (void) prev_arena;
+ (void) actual_size;
return buf.first(actual_size);
}
void _resolve_tags(Tree *t, size_t node) |
Sorry for taking a bit long to look at this, I've been all hands on #414 which has been on the works for a long time; it is gigantic and really hard. So my attention is patchy here. But I agree this issue is serious. This PR is not complete yet. I intend to add tests to verify this, and I still need to search through the library for other places using |
No worries. Just wanted to put it on your radar! Thanks again. |
I sketched the assertion tests in test_tree.cpp. Feel free to continue if this is blocking you. Also, I think it is better to merge this before merging #414 |
Hi @biojppm Thanks for trying to fix the issue. I would like to use the noexcept version, what are the things left to get this PR merged? |
8e46cef
to
795910a
Compare
@Neko-Box-Coder Thanks, that would be nice. I did a major revision of the methods in the node classes. The following things are yet to be done:
Pick your favorite! |
BTW, don't worry about the parser class. The parser has been rewritten in #414, and its contents went to different files, so changing it here (if required) would be pointless. |
@biojppm Anyway, I have replaced Do I just push to your branch (not sure if I can do that) or do I create another PR to merge into this branch ( |
Thanks! I think it has to be a separate PR. |
BTW the failing install tests are because of a dependency. Don't worry about those. |
abf9093
to
57e470b
Compare
which caused asserts to be enabled in release builds thanks to @jdrouhard re #389
@Neko-Box-Coder @jdrouhard It's ready to be merged. Do you have any remarks? |
I tried the current tip of this PR in our codebase and now I'm getting a ton of:
I haven't had a chance to dig in to see if I'm actually using the library incorrectly or not, but these same tests were passing previously. The actual changes here look good to me, though, so it's probably on my end. I'll confirm shortly. |
@jdrouhard remember that this PR not just fixes the |
Looks like I was doing a Not sure it's totally clear that |
You are not the first to fall into this gotcha. In the PR I also improved the states of mutable refs, and now there is
So both Tree tree = parse("{a: b}");
NodeRef invalid; // not pointing at anything.
NodeRef readable = tree["a"]; // also valid
NodeRef seed = tree["none"]; // also valid I think the meaning of In your case, querying |
6cf1530
to
c748eef
Compare
After thinking about it, I opted to keep .valid(), and improved the comments explaining this, and in the quickstart as well. |
c748eef
to
12236b7
Compare
Hi @biojppm |
I definitely agree that I am not totally happy about this state of affairs. So I just had an idea. I am thinking that Picking Would appreciate feedback. @Neko-Box-Coder @jdrouhard what do you think? |
@biojppm |
Works for me. Would the implicit cast to bool of a Assume if (auto child = myNode["child"]; !child) {
child |= ryml::MAP;
// populate a new map, etc....
} The |
On second thought, yeah I think I get what you mean now regarding |
I have just finished reviewing it, only have 1 comment for the code. Also, would it be better to be more explicit for |
Yep, finished testing it. The exception catching is working and it seems good to me. |
Wow, I didn't remember that implicit cast. Thanks for raising the point. That's another foot gun. I am going to deprecate that as well. |
I started trying out this invalid/seed/readable idea, and it is really working so far. Already I caught a handful of cases where It also helps that there is no semantic overlap between any of these three states. Not done yet, but it's all for the better. |
@jdrouhard There is no implicit cast to bool. What I think is happening is that operator==(nullptr_t) is being invoked there. I have to investigate further, but I think that operator is too vague and ambiguous. I am thinking of deprecating that too. |
To be fair, I was using the |
- improve explanation of states - deprecate .valid() - add .readable() state - deprecate operator==(nullptr) - deprecate operator==(csubstr)
af04419
to
4193d93
Compare
@jdrouhard indeed, there was no operator for implicit conversion to bool. That's something I would not do, as it is ambiguous, and with this API the point is to be specific. So that I've finished with the I just pushed it, so let's see whether the CI succeeds, but it is done if the CI succeeds. |
Yep, green enough. Ready to merge. |
Fixes #389
Fixes #362
Fix major error handling problem reported in #389 (PR#411):
NodeRef
andConstNodeRef
classes had many methods markednoexcept
that were doing assertions which could throw exceptions, causing an abort instead of a throw whenever the assertion called an exception-throwing error callback.RYML_USE_ASSERT
was defined to 0. Thanks to @jdrouhard for reporting this.NodeRef
/ConstNodeRef
classes:RYML_USE_ASSERT
- enable assertions regardless of build type. This is disabled by default.RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
- defines the same macro, which will make the default error handler provided by ryml throw exceptions instead of callingstd::abort()
. This is disabled by default.RYML_DEBUG_BREAK()
is now enabled only ifRYML_DBG
is defined, as reported in #362.