From 766ae2d5ea714be2aa7d5d2895319c3070d2403c Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:51:26 +0100 Subject: [PATCH] fix(anki): handle typst compilation warnings --- src/anki/typst_compiler.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/anki/typst_compiler.py b/src/anki/typst_compiler.py index 3aaa504..83cfbad 100644 --- a/src/anki/typst_compiler.py +++ b/src/anki/typst_compiler.py @@ -1,6 +1,8 @@ import asyncio import os import random +import re +import sys from pathlib import Path from typing import List @@ -18,7 +20,7 @@ default_preamble = """ class TypstCompilationError(ValueError): - pass + regex = re.compile(r"\nerror: ") class TypstCompiler: @@ -48,7 +50,11 @@ class TypstCompiler: stdout, stderr = await proc.communicate() os.remove(tmp_path) if stderr: - raise TypstCompilationError(bytes.decode(stderr, encoding="utf-8")) + err = bytes.decode(stderr, encoding="utf-8") + if TypstCompilationError.regex.search("\n" + err): + raise TypstCompilationError(err) + else: + print(f"Typst compilation warning:\n{err}", file=sys.stderr, flush=True) return stdout async def _compile_flashcard(self, card: Flashcard):