Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

fix: make release-mode errors fatal instead of rendering HTML page to production

author: pi66
date: 2026-07-23 15:28
hash: 985cb8228fa5884f50615dbd2fcbd5135bfc2ff9

Diffstat:

M

src/errors.py
28 +++++++++++++++++-------------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
diff --git a/src/errors.py b/src/errors.py
index 8f94fcd..6d863b9 100644
--- a/src/errors.py
+++ b/src/errors.py
@@ -4,6 +4,7 @@ import traceback

 from .log import *
 from . import settings
+from .api import api

 def get_user_frame(exc):
     tb = traceback.extract_tb(exc.__traceback__)
@@ -27,14 +28,24 @@ def get_error_line(exc):
     frame = get_user_frame(exc)
     return frame.line.strip() if frame and frame.line else None

-def term_error(exc, message):
+def fatal(exc, message):
     frame = get_user_frame(exc)
-    if settings.VERBOSE and frame:
+    source_line = get_error_line(exc)
+    detail = str(exc.message) if hasattr(exc, 'message') else str(exc)
+
+    print(f"{RED('!')} {RED(type(exc).__name__)}")
+    if frame:
         print(f"{BLUE(frame.name + '()')} {GRAY('—')} {basename(frame.filename)}:{YELLOW(str(frame.lineno))}")
-        print(f"{GRAY('│')}  {frame.line}\n")
-    warn(message)
+    if detail:
+        print(f"{GRAY('│')}  {detail}")
+    if source_line:
+        print(f"{GRAY('│')}  {source_line}\n")
+    die(message)
+
+def html_fatal(exc, message):
+    if api.mode == "release":
+        fatal(exc, message)

-def web_error(exc, message):
     frame = get_user_frame(exc)
     source_line = get_error_line(exc)
     line = escape(source_line) if source_line else "<i style='color:#666'>line not available</i>"
@@ -68,10 +79,3 @@ def web_error(exc, message):
         </div>
     </body>
     </html>"""
-
-def fatal(exc, message):
-    term_error(exc, message)
-    die(message)
-
-def html_fatal(exc, message):
-    return web_error(exc, message)