From 736047402d4af5bf139df3315fe12b0006a68591 Mon Sep 17 00:00:00 2001 From: object-Object Date: Sat, 2 Sep 2023 16:03:19 -0400 Subject: [PATCH] Better hexdoc_block error message --- doc/src/hexdoc/utils/jinja_extensions.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/src/hexdoc/utils/jinja_extensions.py b/doc/src/hexdoc/utils/jinja_extensions.py index a9cca9b3..a9f12fb8 100644 --- a/doc/src/hexdoc/utils/jinja_extensions.py +++ b/doc/src/hexdoc/utils/jinja_extensions.py @@ -31,6 +31,14 @@ class IncludeRawExtension(Extension): @pass_context def hexdoc_block(context: Context, value: Any) -> str: + try: + return _hexdoc_block(context, value) + except Exception as e: + e.add_note(f"Tried to convert block:\n {value}") + raise + + +def _hexdoc_block(context: Context, value: Any) -> str: match value: case LocalizedStr() | str(): # use Markup to tell Jinja not to escape this string for us @@ -42,7 +50,7 @@ def hexdoc_block(context: Context, value: Any) -> str: with HTMLStream() as out: with value.style.element(out, book.link_bases): for child in value.children: - out.write(hexdoc_block(context, child)) + out.write(_hexdoc_block(context, child)) return Markup(out.getvalue()) case None: