]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/yang.c
Merge pull request #6414 from opensourcerouting/nb-error-handling
[mirror_frr.git] / lib / yang.c
index 7ac39f41824f428c097d92c4148cca9315d4819a..0714ddf7bbb501846b6fd75d517e8d3a4f39eaf9 100644 (file)
@@ -647,6 +647,34 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path)
                zlog(priority, "libyang: %s", msg);
 }
 
+const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len)
+{
+       struct ly_err_item *ei;
+       const char *path;
+
+       ei = ly_err_first(ly_ctx);
+       if (!ei)
+               return "";
+
+       strlcpy(buf, "YANG error(s):\n", buf_len);
+       for (; ei; ei = ei->next) {
+               strlcat(buf, " ", buf_len);
+               strlcat(buf, ei->msg, buf_len);
+               strlcat(buf, "\n", buf_len);
+       }
+
+       path = ly_errpath(ly_ctx);
+       if (path) {
+               strlcat(buf, " YANG path: ", buf_len);
+               strlcat(buf, path, buf_len);
+               strlcat(buf, "\n", buf_len);
+       }
+
+       ly_err_clean(ly_ctx, NULL);
+
+       return buf;
+}
+
 void yang_debugging_set(bool enable)
 {
        if (enable) {