Show manager startup failures using TextWindow (#1310)

* show text window on build failure

* Only show last 10 line

* Fix that

* better layout

* Fix fake text window

* Only show spinner and textwindow on android

Co-authored-by: Comma Device <device@comma.ai>
albatross
Willem Melching 2020-04-02 15:04:01 -07:00 committed by GitHub
parent c95134defe
commit dae19a284d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 8 deletions

View File

@ -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 <module>
main()

View File

@ -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