Skip to content

Commit 1e06cf7

Browse files
committed
show: relay cli-pretty's user-facing error messages
cli-pretty prints a friendly message on stdout before any sys.exit(1) — 'Interface "w" not found', 'Error, top level "ietf-routing:routing" missing', etc. The wrapper used subprocess.run(..., check=True) and on non-zero exit caught CalledProcessError, throwing away the captured stdout and printing the generic exception message instead. Drop the check=True / try-except dance, always relay stdout, and only fall back to the generic 'Error running cli-pretty' line when the subprocess crashed without producing any output. Before: admin@bpi:/> show interface w Error running cli-pretty: Command '['/usr/libexec/statd/cli-pretty', 'show-interfaces', '-n', 'w']' returned non-zero exit status 1. After: admin@bpi:/> show interface w Interface "w" not found Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 528692a commit 1e06cf7

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/bin/show/__init__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,20 @@ def cli_pretty(json_data: dict, command: str, *args: str):
4040
return
4141

4242
safe_args = [shlex.quote(arg) for arg in args]
43-
44-
try:
45-
json_input = json.dumps(json_data) # Keep as string, not bytes
46-
result = subprocess.run([
47-
"/usr/libexec/statd/cli-pretty", command, *safe_args
48-
], input=json_input, capture_output=True, text=True, check=True)
43+
json_input = json.dumps(json_data)
44+
result = subprocess.run([
45+
"/usr/libexec/statd/cli-pretty", command, *safe_args
46+
], input=json_input, capture_output=True, text=True)
47+
48+
# cli-pretty prints a user-facing message on stdout before any
49+
# sys.exit(1) (e.g. 'Interface "w" not found'). Relay it regardless
50+
# of the exit status, and only surface the generic exec error when
51+
# nothing useful was produced.
52+
if result.stdout:
4953
print(result.stdout, end="")
50-
except subprocess.CalledProcessError as e:
51-
print(f"Error running cli-pretty: {e}")
54+
elif result.returncode != 0:
55+
msg = result.stderr.strip() or f"exit status {result.returncode}"
56+
print(f"Error running cli-pretty: {msg}")
5257

5358

5459
def dhcp(args: List[str]) -> None:

0 commit comments

Comments
 (0)