Skip to content

Commit b8fde54

Browse files
authored
automerge: make error-message formatting less amusing. (#35)
The automerge script failed just now (for a benign transient reason), and printed this: ERROR: Failed to run command: "[ ' g i t ' , ' - C ' , ' / h o m e / r u n n e r / w o r k / a r m - t o o l c h a i n / a r m - t o o l c h a i n ' , ' p u s h ' , ' o r i g i n ' , ' a r m - s o f t w a r e ' ]" because `error.cmd` was a list of strings, and the error message tried to format it using `" ".join(str(error.cmd))`, which first converted the list into a single string the same way `__repr__` would have done it (displaying the list in Python syntax with strings quoted), and then applied `" ".join` to the resulting string, which caused it to be treated as a list of characters, and each pair of characters separated with a space. The sensible way to format a shell command in list-of-strings format is `shlex.join`. Funny as the above is, let's use that instead :-)
1 parent 4e13bb8 commit b8fde54

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arm-software/ci/automerge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import json
1010
import logging
11+
import shlex
1112
import subprocess
1213
import sys
1314
from pathlib import Path
@@ -206,7 +207,7 @@ def main():
206207
except subprocess.CalledProcessError as error:
207208
logger.error(
208209
'Failed to run command: "%s"\nstdout:\n%s\nstderr:\n%s',
209-
" ".join(str(error.cmd)),
210+
shlex.join(error.cmd),
210211
error.stdout,
211212
error.stderr,
212213
)

0 commit comments

Comments
 (0)