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 <qwint.42@gmail.com>

* Update WebHostLib/generate.py

Co-authored-by: qwint <qwint.42@gmail.com>

* use f words

* small refactor

* Update WebHostLib/generate.py

Co-authored-by: qwint <qwint.42@gmail.com>

* Fix whitespace.

* Update one new use of seedError template for pickling errors.

---------

Co-authored-by: qwint <qwint.42@gmail.com>
This commit is contained in:
massimilianodelliubaldini
2025-10-05 09:38:57 -04:00
committed by GitHub
parent 8decde0370
commit fd879408f3
4 changed files with 47 additions and 11 deletions

View File

@@ -72,6 +72,10 @@ def generate(race=False):
return render_template("generate.html", race=race, version=__version__) 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]): def start_generation(options: dict[str, dict | str], meta: dict[str, Any]):
results, gen_options = roll_options(options, set(meta["plando_options"])) 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: except PicklingError as e:
from .autolauncher import handle_generation_failure from .autolauncher import handle_generation_failure
handle_generation_failure(e) 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() commit()
@@ -104,7 +112,11 @@ def start_generation(options: dict[str, dict | str], meta: dict[str, Any]):
except BaseException as e: except BaseException as e:
from .autolauncher import handle_generation_failure from .autolauncher import handle_generation_failure
handle_generation_failure(e) 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)) 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: if gen is not None:
gen.state = STATE_ERROR gen.state = STATE_ERROR
meta = json.loads(gen.meta) meta = json.loads(gen.meta)
meta["error"] = ( meta["error"] = ("Allowed time for Generation exceeded, " +
"Allowed time for Generation exceeded, please consider generating locally instead. " + "please consider generating locally instead. " +
e.__class__.__name__ + ": " + str(e)) format_exception(e))
if e.__cause__:
meta["source"] = format_exception(e.__cause__)
gen.meta = json.dumps(meta) gen.meta = json.dumps(meta)
commit() commit()
except BaseException as e: 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: if gen is not None:
gen.state = STATE_ERROR gen.state = STATE_ERROR
meta = json.loads(gen.meta) 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) gen.meta = json.dumps(meta)
commit() commit()
raise raise
@@ -204,7 +220,9 @@ def wait_seed(seed: UUID):
if not generation: if not generation:
return "Generation not found." return "Generation not found."
elif generation.state == STATE_ERROR: 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) return render_template("waitSeed.html", seed_id=seed_id)

View File

@@ -72,3 +72,13 @@ code{
padding-right: 0.25rem; padding-right: 0.25rem;
color: #000000; 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;
}

View File

@@ -13,3 +13,7 @@
min-height: 360px; min-height: 360px;
text-align: center; text-align: center;
} }
h2, h4 {
color: #ffffff;
}

View File

@@ -4,16 +4,20 @@
{% block head %} {% block head %}
<title>Generation failed, please retry.</title> <title>Generation failed, please retry.</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/waitSeed.css") }}"/> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles/waitSeed.css') }}"/>
{% endblock %} {% endblock %}
{% block body %} {% block body %}
{% include 'header/oceanIslandHeader.html' %} {% include 'header/oceanIslandHeader.html' %}
<div id="wait-seed-wrapper" class="grass-island"> <div id="wait-seed-wrapper" class="grass-island">
<div id="wait-seed"> <div id="wait-seed">
<h1>Generation failed</h1> <h1>Generation Failed</h1>
<h2>please retry</h2> <h2>Please try again!</h2>
{{ seed_error }} <p>{{ seed_error }}</p>
<h4>More details:</h4>
<p>
<code class="grassy">{{ details }}</code>
</p>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}