if (operation == NB_OP_CREATE_EXCL) {
snprintf(errmsg, errmsg_len,
"Data already exists");
- ret = NB_ERR;
+ ret = NB_ERR_EXISTS;
goto done;
}
if (!dnode || (dnode->flags & LYD_DEFAULT)) {
if (operation == NB_OP_DELETE) {
snprintf(errmsg, errmsg_len, "Data missing");
- return NB_ERR;
+ return NB_ERR_NOT_FOUND;
} else
return NB_OK;
}
return "no changes";
case NB_ERR_NOT_FOUND:
return "element not found";
+ case NB_ERR_EXISTS:
+ return "element already exists";
case NB_ERR_LOCKED:
return "resource is locked";
case NB_ERR_VALIDATION:
* unlock: implicit-lock flag was set in the request
* commit: implicit-commit flag was set in the request
* xpath: the xpath of the data node that was created
- * error: the error code, zero for successful request
+ * error: >0 LY_ERR, < 0 -errno
* errstr: the error string, if error is non-zero
*/
extern int mgmt_fe_adapter_send_edit_reply(uint64_t session_id, uint64_t txn_id,
* Args:
* txn_id: the txn_id this error pertains to.
* short_circuit_ok: True if OK to short-circuit the call.
- * error: An integer error value.
+ * error: >0 LY_ERR, < 0 -errno
* errfmt: An error format string (i.e., printfrr)
* ...: args for use by the `errfmt` format string.
*
" req_id %" PRIu64 " to requested type %u",
txn->txn_id, req_id, get_tree->result_type);
- (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, ret,
+ (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false,
+ errno_from_nb_error(ret),
"Error converting results of GETTREE");
}
EVENT_OFF(txn->rpc_timeout);
if (rpc->errstr)
- mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, -1,
+ mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, -EINVAL,
rpc->errstr);
else if (mgmt_fe_adapter_send_rpc_reply(txn->session_id, txn->txn_id,
req_id, rpc->result_type,
" req_id %" PRIu64 " to requested type %u",
txn->txn_id, req_id, rpc->result_type);
- (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, -1,
+ (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false,
+ -EINVAL,
"Error converting results of RPC");
}
reply:
mgmt_fe_adapter_send_edit_reply(txn->session_id, txn->txn_id, req_id,
unlock, commit, edit->xpath_created,
- ret ? -1 : 0, errstr);
+ errno_from_nb_error(ret), errstr);
XFREE(MTYPE_MGMTD_TXN_REQ, edit);
return "Unknown";
}
+
+static inline int16_t errno_from_nb_error(enum nb_error ret)
+{
+ switch (ret) {
+ case NB_OK:
+ return 0;
+ case NB_ERR_NO_CHANGES:
+ return -EALREADY;
+ case NB_ERR_NOT_FOUND:
+ return -ENOENT;
+ case NB_ERR_EXISTS:
+ return -EEXIST;
+ case NB_ERR_LOCKED:
+ return -EWOULDBLOCK;
+ case NB_ERR_VALIDATION:
+ return -EINVAL;
+ case NB_ERR_RESOURCE:
+ return -ENOMEM;
+ case NB_ERR:
+ case NB_ERR_INCONSISTENCY:
+ return -EINVAL;
+ case NB_YIELD:
+ default:
+ return -EINVAL;
+ }
+}
+
+
/* Initialise transaction module. */
extern int mgmt_txn_init(struct mgmt_master *cm, struct event_loop *tm);