From 25f7c56c0a5683183f5940afca8853813f7f9531 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Wed, 29 Jan 2025 08:26:39 -0800 Subject: [PATCH] backend: Handle RPC errors Use the new RPC error reporting interface to report RPC errors from plugins. Signed-off-by: Corey Minyard --- apps/backend/backend_client.c | 2 +- apps/backend/backend_commit.c | 4 ++-- apps/backend/backend_plugin.c | 20 +++++++------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 30858e6b..058f536c 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -723,7 +723,7 @@ from_client_edit_config(clixon_handle h, } } if ((ret = candidate_commit(h, NULL, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ - if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) + if (clixon_plugin_report_err(h, cbret) < 0) goto done; xmldb_copy(h, "running", "candidate"); goto ok; diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index 95ba54bf..b2ba3f98 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -637,7 +637,7 @@ candidate_validate(clixon_handle h, * TODO: -1 return should be fatal error, not failed validation */ if (!cbuf_len(cbret) && - netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) + clixon_plugin_report_err(h, cbret) < 0) goto done; goto fail; } @@ -857,7 +857,7 @@ from_client_commit(clixon_handle h, if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ clixon_debug(CLIXON_DBG_BACKEND, "Commit candidate failed"); if (ret < 0) - if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) + if (clixon_plugin_report_err(h, cbret) < 0) goto done; goto ok; } diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 28a3534d..dfc43f54 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -295,7 +295,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, if (fn(h, nsc, xpath, x) < 0){ if (clixon_resource_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; - if (clixon_err_category() < 0) + if (clixon_err_category() < 0 && !clixon_plugin_rpc_err_set(h)) clixon_log(h, LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto fail; /* Dont quit here on user callbacks */ @@ -342,7 +342,6 @@ clixon_plugin_statedata_all(clixon_handle h, int ret; cxobj *x = NULL; clixon_plugin_t *cp = NULL; - cbuf *cberr = NULL; cxobj *xerr = NULL; clixon_debug(CLIXON_DBG_BACKEND | CLIXON_DBG_DETAIL, ""); @@ -350,14 +349,10 @@ clixon_plugin_statedata_all(clixon_handle h, if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0) goto done; if (ret == 0){ - if ((cberr = cbuf_new()) == NULL){ - clixon_err(OE_UNIX, errno, "cbuf_new"); - goto done; - } /* error reason should be in clixon_err_reason */ - cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s", - clixon_plugin_name_get(cp), clixon_err_reason()); - if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) + if (clixon_plugin_report_err_xml(h, &xerr, + "Internal error, state callback in plugin %s returned invalid XML: %s", + clixon_plugin_name_get(cp), clixon_err_reason()) < 0) goto done; xml_free(*xret); *xret = xerr; @@ -406,8 +401,6 @@ clixon_plugin_statedata_all(clixon_handle h, done: if (xerr) xml_free(xerr); - if (cberr) - cbuf_free(cberr); if (x) xml_free(x); return retval; @@ -611,8 +604,9 @@ plugin_transaction_call_one(clixon_handle h, if (clixon_resource_check(h, &wh, clixon_plugin_name_get(cp), fnname) < 0) goto done; if (rv < 0) { - if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ - clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", + if (!clixon_plugin_rpc_err_set(h) && !clixon_err_category()) + /* sanity: log if err is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err or clixon_plugin_rpc_err call on error", fnname, clixon_plugin_name_get(cp)); goto done; }