From f7bf2db958bcd0a81cdd64b7f4dc04e9b50a7d76 Mon Sep 17 00:00:00 2001 From: Spencer Brown Date: Mon, 30 Oct 2023 12:55:16 +1000 Subject: [PATCH] #1893: Add compile logs to error display windows. --- error_display/static/styles.css | 7 +++++ error_display/templates/index.html.jinja2 | 17 +++++++++- src/error_server.py | 38 ++++++++++++++++++----- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/error_display/static/styles.css b/error_display/static/styles.css index 19ddd0d70..6976601dd 100644 --- a/error_display/static/styles.css +++ b/error_display/static/styles.css @@ -23,7 +23,14 @@ main { background-origin: border-box; background-repeat: repeat; color: rgb(201, 211, 207); + overflow-y: scroll; /* Compile dialog uses FriendsListStatusLine: Univers Std Condensed, weight=&00, tall=14 */ } + +details pre { + background: #d7d7d7; + color: black; + white-space: pre-wrap; +} diff --git a/error_display/templates/index.html.jinja2 b/error_display/templates/index.html.jinja2 index 10407d817..cc6481515 100644 --- a/error_display/templates/index.html.jinja2 +++ b/error_display/templates/index.html.jinja2 @@ -16,7 +16,22 @@ {% endif %} -
+ + Chamber Preview +
+ + {% if log_vbsp %} +
+ Geometry Compile Log +
{{ log_vbsp }}
+
+ {% endif %} + {% if log_vrad %} +
+ Lighting / Packing Compile Log +
{{ log_vrad }}
+
+ {% endif %} diff --git a/src/error_server.py b/src/error_server.py index f59e73150..18b06e816 100644 --- a/src/error_server.py +++ b/src/error_server.py @@ -40,6 +40,8 @@ __name__, root_path=str(root_path), ) +# Compile logs. +LOGS = {'vbsp': '', 'vrad': ''} config = Config() config.bind = ["localhost:0"] # Use localhost, request any free port. DELAY = 5 * 60 # After 5 minutes of no response, quit. @@ -57,7 +59,16 @@ async def route_display_errors() -> str: return await quart.render_template( 'index.html.jinja2', error_text=current_error.message.translate_html(), - log_context=current_error.context, + context=current_error.context, + log_vbsp=LOGS['vbsp'], + log_vrad=LOGS['vrad'], + # Start the render visible if it has annotations. + start_render_open=bool( + current_error.points + or current_error.leakpoints + or current_error.lines + or current_error.barrier_hole + ), ) @@ -87,7 +98,7 @@ async def route_heartbeat() -> quart.ResponseReturnValue: async def route_reload() -> quart.ResponseReturnValue: """Called by our VRAD, to make existing servers reload their data.""" update_deadline() - load_info() + await load_info() resp = await app.make_response(('', http.HTTPStatus.NO_CONTENT)) resp.mimetype = 'text/plain' return resp @@ -135,12 +146,11 @@ def ngettext(self, single: str, plural: str, n: int, /) -> str: return self.tokens.get(single.casefold(), single) -def load_info() -> None: +async def load_info() -> None: """Load the error info from disk.""" global current_error try: - with open(DATA_LOC, 'rb') as f: - data = pickle.load(f) + data = pickle.loads(await trio.Path(DATA_LOC).read_bytes()) if not isinstance(data, ErrorInfo): raise ValueError except Exception: @@ -151,8 +161,9 @@ def load_info() -> None: translations: Dict[str, transtoken.GetText] = {} try: - with open('bee2/pack_translation.bin', 'rb') as f: - package_data: List[Tuple[str, Dict[str, str]]] = pickle.load(f) + package_data: List[Tuple[str, Dict[str, str]]] = pickle.loads( + await trio.Path('bee2/pack_translation.bin').read_bytes() + ) except Exception: LOGGER.exception('Failed to load package translations pickle!') else: @@ -186,7 +197,18 @@ async def timeout_func() -> None: # Allow nursery to exit. stop_sleeping.cancel() - load_info() + async def load_compiler(name: str) -> None: + """Load a compiler log file.""" + try: + LOGS[name] = await trio.Path(f'bee2/{name}.log').read_text('utf8') + except OSError: + LOGGER.warning('Could not read bee2/{}.log', name) + + async with trio.open_nursery() as nursery: + nursery.start_soon(load_compiler, 'vbsp') + nursery.start_soon(load_compiler, 'vrad') + nursery.start_soon(load_info) + SERVER_INFO_FILE.unlink(missing_ok=True) try: async with trio.open_nursery() as nursery: