Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit 0df7951

Browse files
ulfalizernashif
authored andcommitted
check_compliance.py: Improve error reporting for Git commands
Similar improvements to zephyrproject-rtos/zephyr#21577. No custom potentially-missing working directory is used here, but always including the exception message still feels more robust. Use err() instead of sys.exit() in git(), and have it include the command name, which is helpful in logs. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent 187a2fc commit 0df7951

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/check_compliance.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ def git(*args):
4040
try:
4141
git_process = subprocess.Popen(
4242
git_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43-
except FileNotFoundError:
44-
sys.exit("git executable not found (when running '{}'). Check that "
45-
"it's in listed in the PATH environment variable"
46-
.format(git_cmd_s))
4743
except OSError as e:
48-
sys.exit("failed to run '{}': {}".format(git_cmd_s, e))
44+
err("failed to run '{}': {}".format(git_cmd_s, e))
4945

5046
stdout, stderr = git_process.communicate()
47+
stdout = stdout.decode("utf-8")
48+
stderr = stderr.decode("utf-8")
5149
if git_process.returncode or stderr:
52-
sys.exit("failed to run '{}': {}".format(
53-
git_cmd_s, stdout.decode("utf-8") + stderr.decode("utf-8")))
50+
err("""\
51+
'{}' exited with status {} (note: output on stderr also counts as a failure).
5452
55-
return stdout.decode("utf-8").rstrip()
53+
==stdout==
54+
{}
55+
==stderr==
56+
{}""".format(git_cmd_s, git_process.returncode, stdout, stderr))
57+
58+
return stdout.rstrip()
5659

5760

5861
# This ends up as None when we're not running in a Zephyr tree
@@ -1272,7 +1275,10 @@ def main():
12721275

12731276

12741277
def err(msg):
1275-
sys.exit("error: " + msg)
1278+
cmd = sys.argv[0] # Empty if missing
1279+
if cmd:
1280+
cmd += ": "
1281+
sys.exit(cmd + "error: " + msg)
12761282

12771283

12781284
if __name__ == "__main__":

0 commit comments

Comments
 (0)