From fd879408f3e419677f23697a1be550cc173e4cb4 Mon Sep 17 00:00:00 2001 From: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> Date: Sun, 5 Oct 2025 09:38:57 -0400 Subject: [PATCH] WebHost: Improve user friendliness of generation failure webpage (#4964) * Improve user friendliness of generation failure webpage. * Add details to other render for seedError.html. * Refactor css to avoid !important tags. * Update WebHostLib/static/styles/themes/ocean-island.css Co-authored-by: qwint * Update WebHostLib/generate.py Co-authored-by: qwint * use f words * small refactor * Update WebHostLib/generate.py Co-authored-by: qwint * Fix whitespace. * Update one new use of seedError template for pickling errors. --------- Co-authored-by: qwint --- WebHostLib/generate.py | 32 +++++++++++++++---- .../static/styles/themes/ocean-island.css | 10 ++++++ WebHostLib/static/styles/waitSeed.css | 4 +++ WebHostLib/templates/seedError.html | 12 ++++--- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/WebHostLib/generate.py b/WebHostLib/generate.py index 6ca8c1c8..a5147f66 100644 --- a/WebHostLib/generate.py +++ b/WebHostLib/generate.py @@ -72,6 +72,10 @@ def generate(race=False): return render_template("generate.html", race=race, version=__version__) +def format_exception(e: BaseException) -> str: + return f"{e.__class__.__name__}: {e}" + + def start_generation(options: dict[str, dict | str], meta: dict[str, Any]): results, gen_options = roll_options(options, set(meta["plando_options"])) @@ -92,7 +96,11 @@ def start_generation(options: dict[str, dict | str], meta: dict[str, Any]): except PicklingError as e: from .autolauncher import handle_generation_failure handle_generation_failure(e) - return render_template("seedError.html", seed_error=("PicklingError: " + str(e))) + meta["error"] = format_exception(e) + if e.__cause__: + meta["source"] = format_exception(e.__cause__) + details = json.dumps(meta, indent=4).strip() + return render_template("seedError.html", seed_error=meta["error"], details=details) commit() @@ -104,7 +112,11 @@ def start_generation(options: dict[str, dict | str], meta: dict[str, Any]): except BaseException as e: from .autolauncher import handle_generation_failure handle_generation_failure(e) - return render_template("seedError.html", seed_error=(e.__class__.__name__ + ": " + str(e))) + meta["error"] = format_exception(e) + if e.__cause__: + meta["source"] = format_exception(e.__cause__) + details = json.dumps(meta, indent=4).strip() + return render_template("seedError.html", seed_error=meta["error"], details=details) return redirect(url_for("view_seed", seed=seed_id)) @@ -175,9 +187,11 @@ def gen_game(gen_options: dict, meta: dict[str, Any] | None = None, owner=None, if gen is not None: gen.state = STATE_ERROR meta = json.loads(gen.meta) - meta["error"] = ( - "Allowed time for Generation exceeded, please consider generating locally instead. " + - e.__class__.__name__ + ": " + str(e)) + meta["error"] = ("Allowed time for Generation exceeded, " + + "please consider generating locally instead. " + + format_exception(e)) + if e.__cause__: + meta["source"] = format_exception(e.__cause__) gen.meta = json.dumps(meta) commit() except BaseException as e: @@ -187,7 +201,9 @@ def gen_game(gen_options: dict, meta: dict[str, Any] | None = None, owner=None, if gen is not None: gen.state = STATE_ERROR meta = json.loads(gen.meta) - meta["error"] = (e.__class__.__name__ + ": " + str(e)) + meta["error"] = format_exception(e) + if e.__cause__: + meta["source"] = format_exception(e.__cause__) gen.meta = json.dumps(meta) commit() raise @@ -204,7 +220,9 @@ def wait_seed(seed: UUID): if not generation: return "Generation not found." elif generation.state == STATE_ERROR: - return render_template("seedError.html", seed_error=generation.meta) + meta = json.loads(generation.meta) + details = json.dumps(meta, indent=4).strip() + return render_template("seedError.html", seed_error=meta["error"], details=details) return render_template("waitSeed.html", seed_id=seed_id) diff --git a/WebHostLib/static/styles/themes/ocean-island.css b/WebHostLib/static/styles/themes/ocean-island.css index 2b45fb9d..3216e5e3 100644 --- a/WebHostLib/static/styles/themes/ocean-island.css +++ b/WebHostLib/static/styles/themes/ocean-island.css @@ -72,3 +72,13 @@ code{ padding-right: 0.25rem; color: #000000; } + +code.grassy { + background-color: #b5e9a4; + border: 1px solid #2a6c2f; + white-space: preserve; + text-align: left; + display: block; + font-size: 14px; + line-height: 20px; +} diff --git a/WebHostLib/static/styles/waitSeed.css b/WebHostLib/static/styles/waitSeed.css index 85d281b2..0b4e4c32 100644 --- a/WebHostLib/static/styles/waitSeed.css +++ b/WebHostLib/static/styles/waitSeed.css @@ -13,3 +13,7 @@ min-height: 360px; text-align: center; } + +h2, h4 { + color: #ffffff; +} diff --git a/WebHostLib/templates/seedError.html b/WebHostLib/templates/seedError.html index a5eec1a4..6953eef6 100644 --- a/WebHostLib/templates/seedError.html +++ b/WebHostLib/templates/seedError.html @@ -4,16 +4,20 @@ {% block head %} Generation failed, please retry. - + {% endblock %} {% block body %} {% include 'header/oceanIslandHeader.html' %}
-

Generation failed

-

please retry

- {{ seed_error }} +

Generation Failed

+

Please try again!

+

{{ seed_error }}

+

More details:

+

+ {{ details }} +

{% endblock %}