From 742cd6bdf264c34ecbcee6a77307057e33a6c5b5 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 20 Feb 2026 10:36:19 +0000 Subject: [PATCH] Add a fallback page template. --- .../server/__init__.py | 3 + .../server/fallback.html.jinja | 178 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 src/openflexure_microscope_server/server/fallback.html.jinja diff --git a/src/openflexure_microscope_server/server/__init__.py b/src/openflexure_microscope_server/server/__init__.py index 62314856..71ef6362 100644 --- a/src/openflexure_microscope_server/server/__init__.py +++ b/src/openflexure_microscope_server/server/__init__.py @@ -7,6 +7,7 @@ import os from argparse import Namespace from copy import copy from functools import wraps +from pathlib import Path from typing import Any, Callable, Optional import uvicorn @@ -31,6 +32,7 @@ from .serve_static_files import add_static_files LOGGER = logging.getLogger(__name__) DEVELOPER_MODE = os.getenv("OFM_SERVER_DEV_MODE", "false").lower() == "true" +_TEMPLATE_PATH = Path(__file__).with_name("fallback.html.jinja") def set_shutdown_function(shutdown_function: Callable[[], None]) -> None: @@ -154,6 +156,7 @@ def serve_from_cli(argv: Optional[list[str]] = None) -> None: log_history = None app = fallback.app + app.set_template_str(_TEMPLATE_PATH.read_text(encoding="utf-8")) app.set_context( fallback.FallbackContext( server=server, config=lt_config, error=e, log_history=log_history diff --git a/src/openflexure_microscope_server/server/fallback.html.jinja b/src/openflexure_microscope_server/server/fallback.html.jinja new file mode 100644 index 00000000..38bc9e4a --- /dev/null +++ b/src/openflexure_microscope_server/server/fallback.html.jinja @@ -0,0 +1,178 @@ + + + + + OpenFlexure Microscope Server Failed to Start + + + + + + + +
+
+ +
+ + + +

The OpenFlexure Microscope Server couldn't start.

+
+ +

+ The OpenFlexure Microscope Server failed during startup. This is + usually caused by an invalid configuration, missing dependency, + or a runtime exception. This page provides logging information for debugging. +

+

+ You can get help with your microscope on the + OpenFlexure Forum + (https://openflexure.discourse.group/). +

+ + {% if error_message %} +
+ {{ error_message }} +
+ {% endif %} + + {% if things %} +

The following Things loaded successfully:

+
    + {% for name in things %} +
  • {{ name }}
  • + {% endfor %} +
+ {% endif %} + +

Configuration

+
{{ config }}
+ +

Traceback

+
{{ traceback }}
+ +

Logging

+ {% if logginginfo %} +
{{ logginginfo }}
+ {% else %} +

No logging information available.

+ {% endif %} +
+ + +
+ +