Skip to content

Commit

Permalink
If a user-error occurs, prepare and expose a zip with the map files a…
Browse files Browse the repository at this point in the history
…nd configs
  • Loading branch information
TeamSpen210 committed Dec 17, 2024
1 parent ceec3c6 commit 959e085
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* The app is now able to handle having music, voicelines etc selected that
aren't defined in loaded packages. Exporting will fail, but no crash will
occur and the selection will still be saved.
* If an error occurs, the compiler will now prepare a zip containing all the
relevant files for debugging the error.

### Bugfixes:
* The case where no voicelines are set is once again handled correctly.
Expand Down
4 changes: 4 additions & 0 deletions error_display/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ window.addEventListener("load", () => {

let heartbeatID = setInterval(fireHeartbeat, FREQ);

document.getElementById("archive-btn").addEventListener("click", () => {
fetch("/open_archive").catch(console.error);
});

// If the window is hidden (including when the Steam Overlay is closed!!), stop sending
// heartbeat messages so the server can die.
document.addEventListener("visibilitychange", () => {
Expand Down
10 changes: 10 additions & 0 deletions error_display/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ details pre {
color: black;
white-space: pre-wrap;
}

aside {
margin-top: 16px;
}

#archive-btn {
display: block;
margin-left: auto;
margin-right: auto;
}
4 changes: 4 additions & 0 deletions error_display/templates/index.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{% if context %}
<aside>{{ context }}</aside>
{% endif %}
<aside>
{{ trans_archive_info }}
<button type=button id="archive-btn">{{ trans_archive_btn }}</button>
</aside>
</article>
<details{{ " open" if start_render_open else "" }} id="render-details">
<summary>Chamber Preview</summary>
Expand Down
15 changes: 14 additions & 1 deletion i18n/BEE2.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/BEEmod/BEE2.4/issues\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -141,6 +141,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
16 changes: 15 additions & 1 deletion i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: es\n"
Expand Down Expand Up @@ -147,6 +147,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down Expand Up @@ -2891,3 +2904,4 @@ msgstr "Recomendado"
#~ "Solo recomendable con la gran sala "
#~ "de observación. Usar con precaución, "
#~ "¡esto puede dar resultados extraños!"

15 changes: 14 additions & 1 deletion i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: BEEMOD2\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n"
Expand Down Expand Up @@ -146,6 +146,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
15 changes: 14 additions & 1 deletion i18n/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja\n"
Expand Down Expand Up @@ -143,6 +143,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
15 changes: 14 additions & 1 deletion i18n/pl.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/BEEmod/BEE2.4/issues\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: 2021-06-07 15:18+0200\n"
"Last-Translator: \n"
"Language: pl\n"
Expand Down Expand Up @@ -147,6 +147,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
15 changes: 14 additions & 1 deletion i18n/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: BEEMOD2\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: 2021-11-18 17:18+0300\n"
"Last-Translator: \n"
"Language: ru\n"
Expand Down Expand Up @@ -147,6 +147,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
15 changes: 14 additions & 1 deletion i18n/zh_cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/BEEmod/BEE2.4/issues\n"
"POT-Creation-Date: 2024-11-08 16:23+1000\n"
"POT-Creation-Date: 2024-12-17 18:35+1000\n"
"PO-Revision-Date: 2019-11-22 10:47+1000\n"
"Last-Translator: Antecer <[email protected]>\n"
"Language: zh\n"
Expand Down Expand Up @@ -146,6 +146,19 @@ msgid ""
"in a browser on this computer to see:"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
"If submitting a bug report, please include this map archive. It contains "
"your level, the displayed preview, relevant log files and configs to help"
" with identifying the issue. "
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid "Open Archive Folder"
msgstr ""

#. This uses HTML syntax.
#: user_errors.py
msgid ""
Expand Down
57 changes: 55 additions & 2 deletions src/error_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"""
from __future__ import annotations


from typing_extensions import override

from zipfile import ZIP_DEFLATED, ZipFile
import functools
import gettext
import http
Expand All @@ -32,7 +33,8 @@

from user_errors import (
ErrorInfo, DATA_LOC, SERVER_INFO_FILE, ServerInfo, PackageTranslations,
TOK_ERR_FAIL_LOAD, TOK_ERR_MISSING, TOK_COOP_SHOWURL,
TOK_ERR_FAIL_LOAD, TOK_ERR_MISSING, TOK_COOP_SHOWURL, TOK_WEBPAGE_ARCHIVE_INFO,
TOK_WEBPAGE_ARCHIVE_BTN,
)
import utils
import transtoken
Expand All @@ -55,6 +57,7 @@
# That happens either if Portal 2 is detected to quit, or if no response is heard from clients
# for DELAY seconds. It starts with an infinite deadline, to ensure there's time to boot the server.
SHUTDOWN_SCOPE = trio.CancelScope(deadline=math.inf)
ARCHIVE_LOC = utils.conf_location('error_dump/map_dump.zip')

current_error = ErrorInfo(message=TOK_ERR_MISSING)

Expand All @@ -69,13 +72,16 @@ async def route_display_errors() -> str:
context=current_error.context,
log_vbsp=LOGS['vbsp'],
log_vrad=LOGS['vrad'],
archive_url=ARCHIVE_LOC.as_uri(),
# 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_holes
),
trans_archive_info=TOK_WEBPAGE_ARCHIVE_INFO,
trans_archive_btn=TOK_WEBPAGE_ARCHIVE_BTN,
)


Expand Down Expand Up @@ -134,6 +140,51 @@ async def route_shutdown() -> quart.ResponseReturnValue:
return 'DONE'


@app.route('/open_archive')
async def route_open_archive() -> quart.ResponseReturnValue:
"""The overlay browser doesn't allow downloads, so open a file explorer window with the file."""
LOGGER.info('Opening map archive.')
utils.display_directory(ARCHIVE_LOC.parent)
return 'OPENED'


async def generate_archive() -> None:
"""Generate a zip containing data useful for solving a compile error."""
with ZipFile(ARCHIVE_LOC, 'w', compression=ZIP_DEFLATED) as archive:
vmf_name: trio.Path | None = None
styled_name: trio.Path | None = None
name_stem = 'unknown_map'
if current_error.vmf_fname_orig is not None:
vmf_name = trio.Path(current_error.vmf_fname_orig)
name_stem = vmf_name.stem
if current_error.vmf_fname_new is not None:
styled_name = trio.Path(current_error.vmf_fname_new)

for file, dest in [
(vmf_name, f'{name_stem}_orig.vmf'),
(styled_name, f'{name_stem}_styled.vmf'),
(trio.Path(DATA_LOC), 'user_error.pickle'),
(trio.Path('bee2/config.dmx'), 'export_config.dmx'),
(trio.Path(utils.conf_location('config/config.vdf')), 'app_config.vdf'),
]:
if file is None:
LOGGER.debug('No file defined for {}', dest)
continue
try:
data = await file.read_bytes()
except FileNotFoundError:
LOGGER.debug('Missing file: {}', file)
else:
await trio.to_thread.run_sync(archive.writestr, dest, data)
for log_key, log_data in LOGS.items():
if data:
await trio.to_thread.run_sync(archive.writestr, log_key + '.log', log_data)
LOGGER.info(
'Generated dump with files:\n{}',
'\n'.join(f'- {info.filename}' for info in archive.filelist),
)


async def check_portal2_running(allow_exit: trio.Event) -> None:
"""Check if Portal 2 is our parent process, and if so exit early when that dies."""
try:
Expand Down Expand Up @@ -267,8 +318,10 @@ async def load_compiler(name: str) -> None:
allow_exit = trio.Event()

SERVER_INFO_FILE.unlink(missing_ok=True)
ARCHIVE_LOC.unlink(missing_ok=True)
try:
async with trio.open_nursery() as nursery:
nursery.start_soon(generate_archive)
nursery.start_soon(check_portal2_running, allow_exit)
await trio.lowlevel.checkpoint()
binds = await nursery.start(functools.partial(
Expand Down
7 changes: 7 additions & 0 deletions src/user_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ def __str__(self) -> str:
'in a browser on this computer to see:'
)

# Used to format the webpage
TOK_WEBPAGE_ARCHIVE_INFO = TransToken.ui(
'If submitting a bug report, please include this map archive. It contains your level, '
'the displayed preview, relevant log files and configs to help with identifying the issue. '
)
TOK_WEBPAGE_ARCHIVE_BTN = TransToken.ui('Open Archive Folder')

# Generic tokens:
TOK_INVALID_PARAM = TransToken.ui(
'Invalid <code>{option}=</code>"<code>{value}</code>" for {kind} "<var>{id}</var>"!'
Expand Down

0 comments on commit 959e085

Please sign in to comment.