Fix error logging when finding a node
It seems there is no other way to fix this other than disabling all
errors.
https://github.com/CESNET/libyang/issues/642
https://github.com/CESNET/libyang/issues/753
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/50
Change-Id: I0bdc9e8d519c5c4613aa45cd4ec26b5835977f7c
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 757c9f4..6431500 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -9,6 +9,7 @@
#include <libyang/Libyang.hpp>
#include <libyang/Tree_Schema.hpp>
#include <string_view>
+#include "UniqueResource.h"
#include "utils.hpp"
#include "yang_schema.hpp"
@@ -197,7 +198,21 @@
{
std::string absPath = location.m_nodes.empty() ? "" : "/";
absPath += pathToAbsoluteSchemaString(location) + "/" + fullNodeName(location, node);
- return m_context->find_path(absPath.c_str());
+
+ // If no node is found find_path prints an error message, so we have to
+ // disable logging
+ // https://github.com/CESNET/libyang/issues/753
+ {
+ int oldOptions;
+ auto logBlocker = make_unique_resource(
+ [&oldOptions]() {
+ oldOptions = libyang::set_log_options(0);
+ },
+ [&oldOptions]() {
+ libyang::set_log_options(oldOptions);
+ });
+ return m_context->find_path(absPath.c_str());
+ }
}
libyang::S_Schema_Node YangSchema::getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const