Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools: ynl: rework the string representation of NlError

In early days of YNL development dumping the NlMsg on errors
was quite useful, as the library itself could have been buggy.
These days increasingly the NlMsg is just taking up screen space
and means nothing to a typical user. Try to format the errors
more in line with how YNL C formats its errors strings.

Before:
$ ynl --family ethtool --do channels-set --json '{}'
Netlink error: Invalid argument
nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
error: -22
extack: {'miss-type': 'header'}

$ ynl --family ethtool --do channels-set --json '{..., "tx-count": 999}'
Netlink error: Invalid argument
nl_len = 88 (72) nl_flags = 0x300 nl_type = 2
error: -22
extack: {'msg': 'requested channel count exceeds maximum', 'bad-attr': '.tx-count'}

After:
$ ynl --family ethtool --do channels-set --json '{}'
Netlink error: Invalid argument {'miss-type': 'header'}

$ ynl --family ethtool --do channels-set --json '{..., "tx-count": 999}'
Netlink error: requested channel count exceeds maximum: Invalid argument {'bad-attr': '.tx-count'}

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20251027192958.2058340-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+10 -1
+10 -1
tools/net/ynl/pyynl/lib/ynl.py
··· 105 105 self.error = -nl_msg.error 106 106 107 107 def __str__(self): 108 - return f"Netlink error: {os.strerror(self.error)}\n{self.nl_msg}" 108 + msg = "Netlink error: " 109 + 110 + extack = self.nl_msg.extack.copy() if self.nl_msg.extack else {} 111 + if 'msg' in extack: 112 + msg += extack['msg'] + ': ' 113 + del extack['msg'] 114 + msg += os.strerror(self.error) 115 + if extack: 116 + msg += ' ' + str(extack) 117 + return msg 109 118 110 119 111 120 class ConfigError(Exception):