Skip to content

Commit 48422f7

Browse files
committed
Do not use os._exit when build-script fatal errors
`os._exit` does not run any cleanup handlers or flush any buffers, which means that we may end up missing helpful log output. It was being used to avoid printing the log analysis when `--help` was passed, but we can have the same behavior by just not using `finally`.
1 parent 725bd91 commit 48422f7

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

utils/build-script

+5-26
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,6 @@ def tar(source, destination):
184184
shell.call(args + [source], stderr=shell.DEVNULL)
185185

186186

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

@@ -825,11 +803,12 @@ def main():
825803
if __name__ == "__main__":
826804
try:
827805
exit_code = main()
828-
except SystemExit as e:
829-
error_code = process_system_exit(e)
830-
os._exit(error_code)
806+
log_analyzer()
807+
except SystemExit:
808+
raise
831809
except KeyboardInterrupt:
832810
sys.exit(1)
833-
finally:
811+
except Exception:
834812
log_analyzer()
813+
raise
835814
sys.exit(exit_code)

0 commit comments

Comments
 (0)