Merge pull request #18384 from LabNConsulting/chopps/suppress-expected-libyang-error-log

lib: suppress libyang logs during expected error result
This commit is contained in:
Donatas Abraitis 2025-03-16 15:12:59 +01:00 committed by GitHub
commit f2245941d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -394,10 +394,17 @@ static enum nb_error nb_op_xpath_to_trunk(const char *xpath_in, char **xpath_out
struct lyd_node **trunk) struct lyd_node **trunk)
{ {
char *xpath = NULL; char *xpath = NULL;
uint32_t llopts = 0;
enum nb_error ret = NB_OK; enum nb_error ret = NB_OK;
LY_ERR err; LY_ERR err;
/*
* Try to instantiate ever shortened paths until one succeeds, suppress
* libyang logs for the expected errors along the way.
*/
darr_in_strdup(xpath, xpath_in); darr_in_strdup(xpath, xpath_in);
ly_temp_log_options(&llopts);
for (;;) { for (;;) {
err = lyd_new_path2(NULL, ly_native_ctx, xpath, NULL, 0, 0, err = lyd_new_path2(NULL, ly_native_ctx, xpath, NULL, 0, 0,
LYD_NEW_PATH_UPDATE, NULL, trunk); LYD_NEW_PATH_UPDATE, NULL, trunk);
@ -409,6 +416,8 @@ static enum nb_error nb_op_xpath_to_trunk(const char *xpath_in, char **xpath_out
break; break;
darr_strlen_fixup(xpath); darr_strlen_fixup(xpath);
} }
ly_temp_log_options(NULL);
if (ret == NB_OK) if (ret == NB_OK)
*xpath_out = xpath; *xpath_out = xpath;
else else
@ -894,9 +903,12 @@ static enum nb_error nb_op_iter_leaf(struct nb_op_yield_state *ys,
return nb_op_libyang_cb_get(ys, nb_node, ni->inner, xpath); return nb_op_libyang_cb_get(ys, nb_node, ni->inner, xpath);
/* Check for new simple get */ /* Check for new simple get */
if (nb_node->cbs.get) if (nb_node->cbs.get) {
/* XXX: need to run through translator */ /* XXX: need to run through translator */
DEBUGD(&nb_dbg_cbs_state, "northbound callback (get): xpath [%s] list_entry [%p]",
xpath, ni->list_entry);
return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner); return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner);
}
data = nb_callback_get_elem(nb_node, xpath, ni->list_entry); data = nb_callback_get_elem(nb_node, xpath, ni->list_entry);
if (data == NULL) if (data == NULL)
@ -932,9 +944,12 @@ static enum nb_error nb_op_iter_leaflist(struct nb_op_yield_state *ys,
return NB_OK; return NB_OK;
/* Check for new simple get */ /* Check for new simple get */
if (nb_node->cbs.get) if (nb_node->cbs.get) {
/* XXX: need to run through translator */ /* XXX: need to run through translator */
DEBUGD(&nb_dbg_cbs_state, "northbound callback (get): xpath [%s] list_entry [%p]",
xpath, ni->list_entry);
return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner); return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner);
}
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_HAS_GET_TREE)) if (CHECK_FLAG(nb_node->flags, F_NB_NODE_HAS_GET_TREE))
/* XXX: need to run through translator */ /* XXX: need to run through translator */