Skip to content

Commit eab6d90

Browse files
Hooleanfelipesanches
authored andcommitted
Fix raw error crashing HTML reporter, add types, and share error helper
There was one call site where we were accidentally passing a raw Exception as a message instead of a serialised summary, which was crashing the HTML reporter. This commit corrects this by serialising at that site, adds more types to Message to automatically warn for this category of issue in the future, and pulls the stack trace formatting code out into a public function to provide more error details in more places.
1 parent 4cc71b3 commit eab6d90

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Lib/fontbakery/checkrunner.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import concurrent.futures
1717
import inspect
1818
import threading
19-
import traceback
2019
from typing import Union, Tuple
2120

2221
from fontbakery.configuration import Configuration
@@ -26,7 +25,7 @@
2625
Identity,
2726
)
2827
from fontbakery.message import Message
29-
from fontbakery.utils import is_negated
28+
from fontbakery.utils import is_negated, format_error
3029
from fontbakery.status import (
3130
Status,
3231
ERROR,
@@ -154,7 +153,7 @@ def _get_check_dependencies(
154153
except Exception as err:
155154
if not self.catch_errors:
156155
raise
157-
status = Subresult(ERROR, Message("error", str(err)))
156+
status = Subresult(ERROR, Message("error", format_error(err)))
158157
return (status, None)
159158

160159
if negate:
@@ -194,7 +193,9 @@ def _get_check_dependencies(
194193
except Exception as error:
195194
if not self.catch_errors:
196195
raise
197-
status = Subresult(ERROR, Message("failed-dependencies", error))
196+
status = Subresult(
197+
ERROR, Message("failed-dependencies", format_error(error))
198+
)
198199
return (status, None)
199200

200201
def _run_check(self, identity: Identity):
@@ -225,10 +226,7 @@ def _run_check(self, identity: Identity):
225226
except Exception as error:
226227
if not self.catch_errors:
227228
raise
228-
message = f"Failed with {type(error).__name__}: {error}\n```\n"
229-
message += "".join(traceback.format_tb(error.__traceback__))
230-
message += "\n```"
231-
subresults = [(ERROR, Message("failed-check", message))]
229+
subresults = [(ERROR, Message("failed-check", format_error(error)))]
232230

233231
result.extend(
234232
[

Lib/fontbakery/message.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
class Message:
88
"""Status messages to be yielded by FontBakeryCheck"""
99

10-
def __init__(self, code, message):
10+
message: str
11+
12+
def __init__(self, code, message: str):
1113
"""
1214
code: (string|number) a check internal, unique code to describe a
1315
specific failure condition. A short string is preferred, it

Lib/fontbakery/utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import subprocess
1818
import sys
19+
import traceback
1920
from typing import Optional
2021
from copy import deepcopy
2122

@@ -860,3 +861,12 @@ def mark_glyphs(ttFont):
860861
if name in class_def and class_def[name] == 3:
861862
marks.append(name)
862863
return marks
864+
865+
866+
def format_error(error: Exception) -> str:
867+
"""Detail an error with name and stack trace for serialisation."""
868+
869+
message = f"Failed with {type(error).__name__}: {error}\n```\n"
870+
message += "".join(traceback.format_tb(error.__traceback__))
871+
message += "\n```"
872+
return message

0 commit comments

Comments
 (0)