Skip to content

Commit 9c4bd12

Browse files
authored
Merge pull request #60685 from WeZZard/bugfix/issue-60684
[build-script] Makes build-script to support None and string object SystemExit.code
2 parents 93a78b4 + 3a897fc commit 9c4bd12

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

utils/build-script

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,28 @@ def tar(source, destination):
182182
shell.call(args + [source], stderr=shell.DEVNULL)
183183

184184

185+
def process_system_exit(e: SystemExit) -> int:
186+
# According to Python's documents, `SystemExit.code` is the exit status
187+
# or error message that is passed to the constructor. (Defaults to None.)
188+
#
189+
# This means that `SystemExit.code` is either `None`, an `int` object or
190+
# a `string` object of error message.
191+
if e.code is None:
192+
# Fallback to 1 if there is no error code but a `SystemExit`.
193+
return 1
194+
try:
195+
numeric_code = int(e.code)
196+
return numeric_code
197+
except ValueError:
198+
# Fallback to 1 if it is an error message and print that message.
199+
print(e)
200+
return 1
201+
finally:
202+
# Fallback to 1 and do nothing, since there is only ValueError as
203+
# expected exception.
204+
return 1
205+
206+
185207
# -----------------------------------------------------------------------------
186208
# Argument Validation
187209

@@ -719,7 +741,8 @@ if __name__ == "__main__":
719741
try:
720742
exit_code = main()
721743
except SystemExit as e:
722-
os._exit(e.code)
744+
error_code = process_system_exit(e)
745+
os._exit(error_code)
723746
except KeyboardInterrupt:
724747
sys.exit(1)
725748
finally:

0 commit comments

Comments
 (0)