-
Notifications
You must be signed in to change notification settings - Fork 108
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
RoNodeMethods should have conditional noexcept #389
Comments
TL;DR: Not an issue with the library.
So relying on a call to the error callback from This means it is your responsibility to ensure that the wanted child/index looking is actually there, so if that may not be the case with your data, you should not use So in your case you should do something like this: // ERROR: not checked in optimized builds.
// aborts if either a or b are invalid names.
ConstNodeRef b = root["a"]["b"];
// OK, no calls to abort if any name is invalid
// (and throws if either is invalid)
ConstNodeRef a = root.find_child("a");
if(!a.valid()) throw YourError("a");
ConstNodeRef b = a.find_child("b");
if(!b.valid()) throw YourError("b");
// etc Having said that, I agree the I'll keep this open to track that issue. Also, I see that there is no |
Self-reminder: clarify this issue on the documentation. |
I think this is actually an issue in rapidyaml. When you install an error handler via I'd like to be able to use this library but I can't let the library cause program termination and would rather handle errors via exceptions, but because of all the There is too much surface area in rapidyaml's API where the error callback is called from a noexcept function. Removing noexcept shouldn't incur much of a performance penalty (if any at all). |
@biojppm (tagging you in case GitHub notifications are messed up). Anyway, the issue seems to be the always inlined property getters and predicates in /** @name node property getters */
/** @{ */
/** returns the data or null when the id is NONE */
C4_ALWAYS_INLINE C4_PURE NodeData const* get() const noexcept { RYML_ASSERT(tree_ != nullptr); return tree_->get(id_); }
/** returns the data or null when the id is NONE */
template<class U=Impl>
C4_ALWAYS_INLINE C4_PURE auto get() noexcept -> _C4_IF_MUTABLE(NodeData*) { RYML_ASSERT(tree_ != nullptr); return tree__->get(id__); }
C4_ALWAYS_INLINE C4_PURE NodeType type() const noexcept { _C4RV(); return tree_->type(id_); }
C4_ALWAYS_INLINE C4_PURE const char* type_str() const noexcept { return tree_->type_str(id_); }
C4_ALWAYS_INLINE C4_PURE csubstr key() const noexcept { _C4RV(); return tree_->key(id_); }
C4_ALWAYS_INLINE C4_PURE csubstr key_tag() const noexcept { _C4RV(); return tree_->key_tag(id_); }
C4_ALWAYS_INLINE C4_PURE csubstr key_ref() const noexcept { _C4RV(); return tree_->key_ref(id_); }
C4_ALWAYS_INLINE C4_PURE csubstr key_anchor() const noexcept { _C4RV(); return tree_->key_anchor(id_); }
C4_ALWAYS_INLINE C4_PURE csubstr val() const noexcept { _C4RV(); return tree_->val(id_); }
// ... |
Sorry, last comment :) There's another issue with this: https://github.com/biojppm/rapidyaml/blob/master/src/c4/yml/common.hpp#L213 diff --git a/src/c4/yml/common.hpp b/src/c4/yml/common.hpp
index f74de9d..c30d733 100644
--- a/src/c4/yml/common.hpp
+++ b/src/c4/yml/common.hpp
@@ -210,7 +210,7 @@ do \
(cb).m_error(msg, sizeof(msg), c4::yml::Location(__FILE__, 0, __LINE__, 0), (cb).m_user_data); \
} \
} while(0)
-#ifdef RYML_USE_ASSERT
+#if RYML_USE_ASSERT
#define _RYML_CB_ASSERT(cb, cond) _RYML_CB_CHECK((cb), (cond))
#else
#define _RYML_CB_ASSERT(cb, cond) do {} while(0) Otherwise, these asserts are triggered even in release builds since |
I am not sure if this is the same issue or not or a similar one. So both However, since we are not allowed to "return", all the options left for us are really just to terminate the program, but in different way ( It would be fine if I can catch it but the I think that's the whole point of I personally think a library should provide the option of handling errors without terminating the program. If I am creating a program that should not be terminating, the only thing I can hope for is I have put checks everytime before I access something, instead of relying on a result or exception catching. But anyway, I think this is a very good library and I really do appreciate it, especially the ability to parse merge keys which is huge (compare to yaml-cpp). Thank you for creating it :) |
@jdrouhard Sorry for the late reply. Notifications are broken for me, and I only saw this now. As for the issue, like I said in my reply to the OP, and as the issue title states, the problem is indeed all the methods in the node class, which should be conditional noexcept. |
@Neko-Box-Coder It does look to be the same problem, where several methods were carpet-bombed with noexcept and shouldn't have been. What is the ryml method calling the error callback? Is that method Otherwise, please post a minimal example reproducing your problem. |
which caused asserts to be enabled in release builds thanks to @jdrouhard re #389
@biojppm There are a few ones that are calling error callback but I don't remember all. test:
# Commented out child
# test-child: test-value Then it will error out with |
which caused asserts to be enabled in release builds thanks to @jdrouhard re #389
which caused asserts to be enabled in release builds thanks to @jdrouhard re #389
Throwing error callback
may lead to abort() in that case
bacuse noexcept operator[] calls this callback
I saw you mentioned that I can't return from error callback, so basically I can either call abort() or throw an exception, which in turn also leads to abort(). Config parsing error is an expected scenario in my case. So I'd like to handle such errors(even in debug build), rather than crashing the whole app
The text was updated successfully, but these errors were encountered: