diff options
| author | Santosh P K <50885001+Spantik@users.noreply.github.com> | 2020-06-10 22:47:07 +0530 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-10 22:47:07 +0530 | 
| commit | 57dd2f009739664cbf857a82e7a6970c916b8e10 (patch) | |
| tree | 7187878d1394bbc452ecc1e2bffd5edafb9a920d /lib/yang.c | |
| parent | 5e0494b38a53e5a3501088efb4b48b2cbb7a080f (diff) | |
| parent | 1abe6c535e89f8b445c7d5808bc7972a6b60236d (diff) | |
Merge pull request #6414 from opensourcerouting/nb-error-handling
NB context + enhanced error handling
Diffstat (limited to 'lib/yang.c')
| -rw-r--r-- | lib/yang.c | 28 | 
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c index 7ac39f4182..0714ddf7bb 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -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) {  | 
