diff options
| author | Christian Hopps <chopps@labn.net> | 2023-04-17 01:29:33 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2023-04-17 02:15:32 -0400 |
| commit | d249d7e0aba5bc58af2526f846d7ebcf1e817ab8 (patch) | |
| tree | a1ace8a6e62c0948a5d79314e79eec2701022d93 /lib/northbound_cli.c | |
| parent | 4ac51e2430f099bc4f4881e4a83b5ea13c418131 (diff) | |
lib: always return valid data format for show yang command.
For JSON return `{}` for XPath return an XML comment `<!-- Not found -->`
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/northbound_cli.c')
| -rw-r--r-- | lib/northbound_cli.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 5cf5f93b43..c5582fc21c 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -1434,6 +1434,7 @@ DEFPY (show_yang_operational_data, struct lyd_node *dnode; char *strp; uint32_t print_options = LYD_PRINT_WITHSIBLINGS; + int ret; if (xml) format = LYD_XML; @@ -1454,10 +1455,15 @@ DEFPY (show_yang_operational_data, /* Obtain data. */ dnode = yang_dnode_new(ly_ctx, false); - if (nb_oper_data_iterate(xpath, translator, 0, nb_cli_oper_data_cb, - dnode) - != NB_OK) { - vty_out(vty, "%% Failed to fetch operational data.\n"); + ret = nb_oper_data_iterate(xpath, translator, 0, nb_cli_oper_data_cb, + dnode); + if (ret != NB_OK) { + if (format == LYD_JSON) + vty_out(vty, "{}\n"); + else { + /* embed ly_last_errmsg() when we get newer libyang */ + vty_out(vty, "<!-- Not found -->\n"); + } yang_dnode_free(dnode); return CMD_WARNING; } |
