diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2020-05-14 12:30:34 -0300 | 
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2020-05-28 19:22:54 -0300 | 
| commit | df5eda3d8783a3436f43821a2840911d610fd89d (patch) | |
| tree | 49cef5931b240472e6ac5b1c78da9fad2ccee0cf /lib/yang.c | |
| parent | 13d6b9c1343a1f925e3ffd7be0938bf1f395b461 (diff) | |
lib: return human-readable error messages to the northbound clients
Instead of returning only error codes (e.g. NB_ERR_VALIDATION)
to the northbound clients, do better than that and also return
a human-readable error message. This should make FRR more
automation-friendly since operators won't need to dig into system
logs to find out what went wrong in the case of an error.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
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 c80bf20306..5fca686c5a 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -621,6 +621,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) {  | 
