backend: Handle RPC errors

Use the new RPC error reporting interface to report RPC errors from
plugins.

Signed-off-by: Corey Minyard <minyard@acm.org>
This commit is contained in:
Corey Minyard 2025-01-29 08:26:39 -08:00 committed by Olof Hagsand
parent 9bdacc8671
commit 25f7c56c0a
3 changed files with 10 additions and 16 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}