Added format string to clicon_rpc_generate_error() and used that to make better backend error messages
This commit is contained in:
parent
936268b813
commit
becddfab41
5 changed files with 26 additions and 30 deletions
|
|
@ -538,10 +538,8 @@ cli_commit(clicon_handle h,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
if ((retval = clicon_rpc_commit(h)) < 0){ /* startup */
|
if ((retval = clicon_rpc_commit(h)) < 0)
|
||||||
cli_output(stderr, "Commit failed. Edit and try again or discard changes");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -659,13 +657,13 @@ compare_dbs(clicon_handle h,
|
||||||
if (clicon_rpc_get_config(h, "running", "/", &xc1) < 0)
|
if (clicon_rpc_get_config(h, "running", "/", &xc1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xc1, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xc1, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_rpc_get_config(h, "candidate", "/", &xc2) < 0)
|
if (clicon_rpc_get_config(h, "candidate", "/", &xc2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xc2, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xc2, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
|
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
|
||||||
|
|
@ -836,7 +834,7 @@ save_config_file(clicon_handle h,
|
||||||
if (clicon_rpc_get_config(h, dbstr,"/", &xt) < 0)
|
if (clicon_rpc_get_config(h, dbstr,"/", &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((f = fopen(filename, "wb")) == NULL){
|
if ((f = fopen(filename, "wb")) == NULL){
|
||||||
|
|
@ -1180,7 +1178,7 @@ cli_copy_config(clicon_handle h,
|
||||||
if (clicon_rpc_get_config(h, db, cbuf_get(cb), &x1) < 0)
|
if (clicon_rpc_get_config(h, db, cbuf_get(cb), &x1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(x1, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(x1, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,6 @@ cli_handler_err(FILE *f)
|
||||||
if (clicon_suberrno)
|
if (clicon_suberrno)
|
||||||
cli_output(f, ": %s", strerror(clicon_suberrno));
|
cli_output(f, ": %s", strerror(clicon_suberrno));
|
||||||
cli_output(f, "\n");
|
cli_output(f, "\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cli_output(f, "CLI command error\n");
|
cli_output(f, "CLI command error\n");
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ expand_dbvar(void *h,
|
||||||
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
|
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
xcur = xt; /* default top-of-tree */
|
xcur = xt; /* default top-of-tree */
|
||||||
|
|
@ -481,7 +481,7 @@ cli_show_config(clicon_handle h,
|
||||||
if (clicon_rpc_get_config(h, db, cbuf_get(cbxpath), &xt) < 0)
|
if (clicon_rpc_get_config(h, db, cbuf_get(cbxpath), &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Print configuration according to format */
|
/* Print configuration according to format */
|
||||||
|
|
@ -565,7 +565,7 @@ show_conf_xpath(clicon_handle h,
|
||||||
if (clicon_rpc_get_config(h, str, xpath, &xt) < 0)
|
if (clicon_rpc_get_config(h, str, xpath, &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Get configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (xpath_vec(xt, xpath, &xv, &xlen) < 0)
|
if (xpath_vec(xt, xpath, &xv, &xlen) < 0)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ int clicon_rpc_msg(clicon_handle h, struct clicon_msg *msg, cxobj **xret0,
|
||||||
int *sock0);
|
int *sock0);
|
||||||
int clicon_rpc_netconf(clicon_handle h, char *xmlst, cxobj **xret, int *sp);
|
int clicon_rpc_netconf(clicon_handle h, char *xmlst, cxobj **xret, int *sp);
|
||||||
int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp);
|
int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp);
|
||||||
int clicon_rpc_generate_error(cxobj *xerr);
|
int clicon_rpc_generate_error(char *format, cxobj *xerr);
|
||||||
int clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, cxobj **xret);
|
int clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, cxobj **xret);
|
||||||
int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op,
|
int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op,
|
||||||
char *xml);
|
char *xml);
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,8 @@ clicon_rpc_netconf_xml(clicon_handle h,
|
||||||
* @param[in] xerr Netconf error message on the level: <rpc-reply><rpc-error>
|
* @param[in] xerr Netconf error message on the level: <rpc-reply><rpc-error>
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clicon_rpc_generate_error(cxobj *xerr)
|
clicon_rpc_generate_error(char *format,
|
||||||
|
cxobj *xerr)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cbuf *cb = NULL;
|
cbuf *cb = NULL;
|
||||||
|
|
@ -217,7 +218,7 @@ clicon_rpc_generate_error(cxobj *xerr)
|
||||||
cprintf(cb, "%s ", xml_body(x));
|
cprintf(cb, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, "error-info"))!=NULL)
|
if ((x=xpath_first(xerr, "error-info"))!=NULL)
|
||||||
clicon_xml2cbuf(cb, xml_child_i(x,0), 0, 0);
|
clicon_xml2cbuf(cb, xml_child_i(x,0), 0, 0);
|
||||||
clicon_err_fn("Clixon", 0, OE_XML, 0, "%s", cbuf_get(cb));
|
clicon_log(LOG_ERR, "%s: %s", format, cbuf_get(cb));
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (cb)
|
if (cb)
|
||||||
|
|
@ -239,7 +240,7 @@ clicon_rpc_generate_error(cxobj *xerr)
|
||||||
* if (clicon_rpc_get_config(h, "running", "/", &xt) < 0)
|
* if (clicon_rpc_get_config(h, "running", "/", &xt) < 0)
|
||||||
* err;
|
* err;
|
||||||
* if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
* if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||||
* clicon_rpc_generate_error(xerr);
|
* clicon_rpc_generate_error("", xerr);
|
||||||
* err;
|
* err;
|
||||||
* }
|
* }
|
||||||
* if (xt)
|
* if (xt)
|
||||||
|
|
@ -330,7 +331,7 @@ clicon_rpc_edit_config(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Editing configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -370,7 +371,7 @@ clicon_rpc_copy_config(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Copying configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -404,7 +405,7 @@ clicon_rpc_delete_config(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Deleting configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -434,7 +435,7 @@ clicon_rpc_lock(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Locking configuration", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -464,7 +465,7 @@ clicon_rpc_unlock(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Configuration unlock", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -556,7 +557,7 @@ clicon_rpc_close_session(clicon_handle h)
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Close session", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -586,7 +587,7 @@ clicon_rpc_kill_session(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Kill session", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -611,15 +612,13 @@ clicon_rpc_validate(clicon_handle h,
|
||||||
struct clicon_msg *msg = NULL;
|
struct clicon_msg *msg = NULL;
|
||||||
cxobj *xret = NULL;
|
cxobj *xret = NULL;
|
||||||
cxobj *xerr;
|
cxobj *xerr;
|
||||||
cxobj *x;
|
|
||||||
|
|
||||||
if ((msg = clicon_msg_encode("<rpc><validate><source><%s/></source></validate></rpc>", db)) == NULL)
|
if ((msg = clicon_msg_encode("<rpc><validate><source><%s/></source></validate></rpc>", db)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
x=xpath_first(xerr, "error-message");
|
clicon_rpc_generate_error("Validate failed. Edit and try again or discard changes", xerr);
|
||||||
clicon_log(LOG_ERR, "Validate failed: \"%s\". Edit and try again or discard changes", x?xml_body(x):"");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -648,7 +647,7 @@ clicon_rpc_commit(clicon_handle h)
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Commit failed. Edit and try again or discard changes", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -677,7 +676,7 @@ clicon_rpc_discard_changes(clicon_handle h)
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Discard changes", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -716,7 +715,7 @@ clicon_rpc_create_subscription(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, s0) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, s0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Create subscription", xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -746,7 +745,7 @@ clicon_rpc_debug(clicon_handle h,
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||||
clicon_rpc_generate_error(xerr);
|
clicon_rpc_generate_error("Debug",xerr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (xpath_first(xret, "//rpc-reply/ok") == NULL){
|
if (xpath_first(xret, "//rpc-reply/ok") == NULL){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue