Skip to content

Commit 77da4af

Browse files
committed
fix unhandled exc in git cmd
1 parent 8944d14 commit 77da4af

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

tools/makecorever.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ def check_git(*args: str, cwd: Optional[str]):
4141
cmd.extend(["-C", cwd])
4242
cmd.extend(args)
4343

44-
with subprocess.Popen(
45-
cmd,
46-
stdout=subprocess.PIPE,
47-
universal_newlines=True,
48-
stderr=subprocess.DEVNULL,
49-
) as proc:
50-
if proc.stdout:
51-
return proc.stdout.readlines()[0].strip()
44+
try:
45+
with subprocess.Popen(
46+
cmd,
47+
stdout=subprocess.PIPE,
48+
universal_newlines=True,
49+
stderr=subprocess.DEVNULL,
50+
) as proc:
51+
if proc.stdout:
52+
lines = proc.stdout.readlines()
53+
return lines[0].strip()
54+
except IndexError:
55+
pass
56+
except FileNotFoundError:
57+
pass
5258

5359
return ""
5460

@@ -68,10 +74,7 @@ def git(*args):
6874
return check_git(*args, cwd=git_cwd)
6975

7076
git_ver = "0" * hash_length
71-
try:
72-
git_ver = git("rev-parse", f"--short={hash_length}", "HEAD")
73-
except Exception:
74-
raise
77+
git_ver = git("rev-parse", f"--short={hash_length}", "HEAD") or git_ver
7578

7679
# version is
7780
# - using Arduino-CLI:
@@ -80,22 +83,20 @@ def git(*args):
8083
# - using git:
8184
# - 5.6.7 (from release script, official release)
8285
# - 5.6.7-42-g00d1e5 (from release script, test release)
83-
git_desc = version
84-
try:
85-
# in any case, get a better version when git is around
86-
git_desc = git("describe", "--tags")
87-
except Exception:
88-
raise
86+
87+
# in any case, get a better version when git is around
88+
git_desc = git("describe", "--tags") or version
8989

9090
if version == VERSION_UNSPECIFIED:
9191
version = git_desc
9292

9393
version_triple = list(VERSION_DEFAULT)
9494

95-
try:
96-
version_triple = version.split(".", 2)
97-
except ValueError:
98-
pass
95+
if version != VERSION_UNSPECIFIED:
96+
try:
97+
version_triple = version.split(".", 2)
98+
except ValueError:
99+
pass
99100

100101
major, minor, patch = version_triple
101102

0 commit comments

Comments
 (0)