messages CHANGE remove nc_err_libyang
diff --git a/src/messages_server.c b/src/messages_server.c
index 197d5f4..8bcea89 100644
--- a/src/messages_server.c
+++ b/src/messages_server.c
@@ -479,161 +479,6 @@
     return NULL;
 }
 
-API struct lyd_node *
-nc_err_libyang(struct ly_ctx *ctx)
-{
-    struct lyd_node *e, *other;
-    const char *str, *stri, *strj, *strk, *strl, *uniqi, *uniqj;
-    char *attr, *path;
-    int len;
-
-    if (!ly_errcode(ctx)) {
-        /* LY_SUCCESS */
-        return NULL;
-    } else if ((ly_errcode(ctx) == LY_EVALID) && (ly_vecode(ctx) == LYVE_DATA)) {
-        /* RFC 7950 section 15 errors */
-        if (!strncmp(ly_errmsg(ctx), "Unique data", 11)) {
-            e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-            nc_err_set_app_tag(e, "data-not-unique");
-            nc_err_set_path(e, ly_errpath(ctx));
-
-            /* parse the message and get all the information we need */
-            str = ly_errmsg(ctx);
-            uniqi = strchr(str, '"');
-            uniqi++;
-            uniqj = strchr(uniqi, '"');
-
-            stri = strchr(uniqj + 1, '"');
-            stri++;
-            strj = strchr(stri, '"');
-
-            strk = strchr(strj + 1, '"');
-            ++strk;
-            strl = strchr(strk, '"');
-
-            /* maximum length is the whole unique string with the longer list instance identifier */
-            len = (uniqj - uniqi) + (strj - stri > strl - strk ? strj - stri : strl - strk);
-            path = malloc(len + 1);
-            if (!path) {
-                ERRMEM;
-                return e;
-            }
-
-            /* create non-unique elements, one in 1st list, one in 2nd list, for each unique list */
-            while (1) {
-                uniqj = strpbrk(uniqi, " \"");
-
-                sprintf(path, "%.*s/%.*s", (int)(strj - stri), stri, (int)(uniqj - uniqi), uniqi);
-                if (lyd_new_opaq2(NULL, ctx, "non-unique", path, NULL, "urn:ietf:params:xml:ns:yang:1", &other)) {
-                    free(path);
-                    return e;
-                }
-                nc_err_add_info_other(e, other);
-
-                sprintf(path, "%.*s/%.*s", (int)(strl - strk), strk, (int)(uniqj - uniqi), uniqi);
-                if (lyd_new_opaq2(NULL, ctx, "non-unique", path, NULL, "urn:ietf:params:xml:ns:yang:1", &other)) {
-                    free(path);
-                    return e;
-                }
-                nc_err_add_info_other(e, other);
-
-                if (uniqj[0] == '"') {
-                    break;
-                }
-                uniqi = uniqj + 1;
-            }
-            free(path);
-        } else if (!strncmp(ly_errmsg(ctx), "Too many", 8)) {
-            e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-            nc_err_set_app_tag(e, "too-many-elements");
-            nc_err_set_path(e, ly_errpath(ctx));
-        } else if (!strncmp(ly_errmsg(ctx), "Too few", 7)) {
-            e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-            nc_err_set_app_tag(e, "too-few-elements");
-            nc_err_set_path(e, ly_errpath(ctx));
-        } else if (!strncmp(ly_errmsg(ctx), "Must condition", 14)) {
-            e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-            if (ly_errapptag(ctx)) {
-                nc_err_set_app_tag(e, ly_errapptag(ctx));
-            } else {
-                nc_err_set_app_tag(e, "must-violation");
-            }
-            nc_err_set_path(e, ly_errpath(ctx));
-        } else if (!strncmp(ly_errmsg(ctx), "Invalid leafref", 15) ||
-                !strncmp(ly_errmsg(ctx), "Invalid instance-identifier", 27)) {
-            e = nc_err(ctx, NC_ERR_DATA_MISSING);
-            nc_err_set_app_tag(e, "instance-required");
-            nc_err_set_path(e, ly_errpath(ctx));
-        } else if (!strncmp(ly_errmsg(ctx), "Mandatory choice", 16)) {
-            e = nc_err(ctx, NC_ERR_DATA_MISSING);
-            nc_err_set_app_tag(e, "missing-choice");
-            nc_err_set_path(e, ly_errpath(ctx));
-
-            str = ly_errmsg(ctx);
-            stri = strchr(str, '"');
-            stri++;
-            strj = strchr(stri, '"');
-            path = strndup(stri, strj - stri);
-
-            if (lyd_new_opaq2(NULL, ctx, "missing-choice", path, NULL, "urn:ietf:params:xml:ns:yang:1", &other)) {
-                free(path);
-                return e;
-            }
-            nc_err_add_info_other(e, other);
-            free(path);
-        } else if (!strncmp(ly_errmsg(ctx), "Unexpected data", 15)) {
-            str = ly_errpath(ctx);
-            if (!str || !strcmp(str, "/")) {
-                e = nc_err(ctx, NC_ERR_OP_NOT_SUPPORTED, NC_ERR_TYPE_APP);
-                /* keep default message */
-                return e;
-            } else {
-                e = nc_err(ctx, NC_ERR_UNKNOWN_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
-            }
-        } else if (!strncmp(ly_errmsg(ctx), "Mandatory node", 14)) {
-            e = nc_err(ctx, NC_ERR_MISSING_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
-        } else if (!strncmp(ly_errmsg(ctx), "Duplicate instance", 18) || !strncmp(ly_errmsg(ctx), "Data for both cases", 19)) {
-            e = nc_err(ctx, NC_ERR_BAD_ELEM, NC_ERR_TYPE_PROT, ly_errpath(ctx));
-        /*case LYVE_INATTR:
-        case LYVE_MISSATTR:
-        case LYVE_INMETA:
-            str = ly_errmsg(ctx);
-            stri = strchr(str, '"');
-            stri++;
-            if (!strncmp(stri, "<none>:", 7)) {
-                stri += 7;
-            }
-            strj = strchr(stri, '"');
-            strj--;
-            attr = strndup(stri, (strj - stri) + 1);
-            if (ly_vecode(ctx) == LYVE_INATTR) {
-                e = nc_err(ctx, NC_ERR_UNKNOWN_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
-            } else if (ly_vecode(ctx) == LYVE_MISSATTR) {
-                e = nc_err(ctx, NC_ERR_MISSING_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
-            } else { * LYVE_INMETA *
-                e = nc_err(ctx, NC_ERR_BAD_ATTR, NC_ERR_TYPE_PROT, attr, ly_errpath(ctx));
-            }
-            free(attr);
-            break;*/
-        } else if (!strncmp(ly_errmsg(ctx), "When condition", 14) || !strncmp(ly_errmsg(ctx), "Unsatisfied pattern", 19) ||
-                !strncmp(ly_errmsg(ctx), "Unsatisfied length", 18) || !strncmp(ly_errmsg(ctx), "Unsatisfied range", 17)) {
-            e = nc_err(ctx, NC_ERR_INVALID_VALUE, NC_ERR_TYPE_PROT);
-            /* length, range, pattern can have a specific error-app-tag */
-            if (ly_errapptag(ctx)) {
-                nc_err_set_app_tag(e, ly_errapptag(ctx));
-            }
-            nc_err_set_path(e, ly_errpath(ctx));
-        } else {
-            e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-        }
-    } else {
-        /* non-validation (internal) error */
-        e = nc_err(ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
-    }
-    nc_err_set_msg(e, ly_errmsg(ctx), "en");
-    return e;
-}
-
 API NC_ERR_TYPE
 nc_err_get_type(const struct lyd_node *err)
 {
diff --git a/src/messages_server.h b/src/messages_server.h
index f58692a..08e0d5f 100644
--- a/src/messages_server.h
+++ b/src/messages_server.h
@@ -170,17 +170,6 @@
 struct lyd_node *nc_err(const struct ly_ctx *ctx, NC_ERR tag, ...);
 
 /**
- * @brief Create a server error structure based on libyang error.
- *
- * The function should be used immediately when a libyang function fails to generate
- * NETCONF error structure based on internal libyang error information (ly_errno, ly_errmsg, ...)
- *
- * @param[in] ctx Libyang context to read the error from.
- * @return Error opaque data node tree.
- */
-struct lyd_node *nc_err_libyang(struct ly_ctx *ctx);
-
-/**
  * @brief Get the \<error-type\> of a server error.
  *
  * @param[in] err Error opaque data node tree to read from.
diff --git a/src/session_server.c b/src/session_server.c
index 4b7ab69..2f9d8cf 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -1265,6 +1265,7 @@
 {
     struct ly_in *msg;
     struct nc_server_reply *reply = NULL;
+    struct lyd_node *e;
     int r, ret;
 
     if (!session) {
@@ -1305,7 +1306,9 @@
 
         if ((*rpc)->envp) {
             /* at least the envelopes were parsed */
-            reply = nc_server_reply_err(nc_err_libyang(server_opts.ctx));
+            e = nc_err(server_opts.ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
+            nc_err_set_msg(e, ly_errmsg(server_opts.ctx), "en");
+            reply = nc_server_reply_err(e);
         } else if (session->version == NC_VERSION_11) {
             /* completely malformed message, NETCONF version 1.1 defines sending error reply from the server (RFC 6241 sec. 3) */
             reply = nc_server_reply_err(nc_err(server_opts.ctx, NC_ERR_MALFORMED_MSG));