diff --git a/common/text_window.py b/common/text_window.py index bc30e135a3..0d94bc7470 100755 --- a/common/text_window.py +++ b/common/text_window.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import os +import time import subprocess from common.basedir import BASEDIR @@ -29,6 +30,12 @@ class TextWindow(): self.text_proc.terminate() self.text_proc = None + def wait_for_exit(self): + while True: + if self.get_status() == 1: + return + time.sleep(0.1) + def __del__(self): self.close() @@ -37,11 +44,14 @@ class TextWindow(): class FakeTextWindow(): - def __init__(self): + def __init__(self, s): pass def get_status(self): - return None + return 1 + + def wait_for_exit(self): + return def __enter__(self): return self @@ -54,7 +64,6 @@ class FakeTextWindow(): if __name__ == "__main__": - import time text = """Traceback (most recent call last): File "./controlsd.py", line 608, in main() diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 2bbc5cde67..a5d853ad0f 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -8,6 +8,7 @@ import signal import shutil import subprocess import datetime +import textwrap from selfdrive.swaglog import cloudlog, add_logentries_handler from common.basedir import BASEDIR, PARAMS @@ -66,9 +67,13 @@ def unblock_stdout(): if __name__ == "__main__": unblock_stdout() + +if __name__ == "__main__" and ANDROID: from common.spinner import Spinner + from common.text_window import TextWindow else: from common.spinner import FakeSpinner as Spinner + from common.text_window import FakeTextWindow as TextWindow import importlib import traceback @@ -126,11 +131,15 @@ if not prebuilt: # Build failed log errors errors = [line.decode('utf8', 'replace') for line in compile_output if any([err in line for err in [b'error: ', b'not found, needed by target']])] - errors = "\n".join(errors) + error_s = "\n".join(errors) add_logentries_handler(cloudlog) - cloudlog.error("scons build failed\n" + errors) + cloudlog.error("scons build failed\n" + error_s) + + # Show TextWindow + error_s = "\n \n".join(["\n".join(textwrap.wrap(e, 65)) for e in errors]) + with TextWindow("Openpilot failed to build\n \n" + error_s) as t: + t.wait_for_exit() - # TODO: Show errors in TextWindow exit(1) else: break @@ -589,8 +598,13 @@ if __name__ == "__main__": except Exception: add_logentries_handler(cloudlog) cloudlog.exception("Manager failed to start") - # TODO: Show exception using TextWindow - # error = traceback.format_exc() + + # Show last 3 lines of traceback + error = traceback.format_exc(3) + + error = "Manager failed to start\n \n" + error + with TextWindow(error) as t: + t.wait_for_exit() raise