|
4 | 4 | import sys |
5 | 5 | from io import BytesIO |
6 | 6 | from pathlib import Path |
| 7 | +from subprocess import CalledProcessError |
7 | 8 | from tempfile import TemporaryDirectory |
8 | 9 |
|
9 | 10 | import discord |
@@ -112,7 +113,9 @@ async def _ensure_typst_executable(self) -> None: |
112 | 113 | stderr=asyncio.subprocess.PIPE, |
113 | 114 | ) |
114 | 115 | stdout, _ = await proc.communicate() |
115 | | - log.info(f"Typst executable reports itself as {stdout.decode('utf-8').strip()!r}.") |
| 116 | + log.info( |
| 117 | + f"Typst executable reports itself as {stdout.decode('utf-8').strip()!r}." |
| 118 | + ) |
116 | 119 |
|
117 | 120 | async def _download_typst_executable(self) -> None: |
118 | 121 | if not Config.typst_archive_url: |
@@ -200,7 +203,6 @@ async def typst(self, ctx: commands.Context, *, query: str) -> None: |
200 | 203 | ) |
201 | 204 | return |
202 | 205 | except TypstWorkerCrashedError: |
203 | | - log.exception("typst worker crashed") |
204 | 206 | await ctx.send( |
205 | 207 | "Worker process crashed. " |
206 | 208 | f"Perhaps the memory limit of {TYPST_MEMORY_LIMIT/1024**2:.1f}MB was exceeded?" |
@@ -228,12 +230,19 @@ async def render_typst( |
228 | 230 | mem_rlimit=TYPST_MEMORY_LIMIT, |
229 | 231 | jobs=WORKER_JOBS, |
230 | 232 | ) |
231 | | - except RuntimeError as e: |
232 | | - raise InvalidTypstError( |
233 | | - e.args[0] if e.args else "<no error message emitted>" |
234 | | - ) |
235 | 233 | except TimeoutError: |
236 | 234 | raise TypstTimeoutError |
| 235 | + except CalledProcessError as e: |
| 236 | + err = e.stderr.decode("utf-8") |
| 237 | + # when the memory limit is reached this usually shows up as signal 6 (SIGABRT), but it can vary |
| 238 | + if e.returncode < 0: |
| 239 | + log.debug( |
| 240 | + "Typst subprocess died due to a signal %s", |
| 241 | + str(e).split("died with")[-1].strip(), |
| 242 | + ) |
| 243 | + raise TypstWorkerCrashedError |
| 244 | + # if in doubt we assume it's a normal error and return the logs |
| 245 | + raise InvalidTypstError(err) |
237 | 246 |
|
238 | 247 | raw_img = res.output |
239 | 248 | if len(raw_img) > MAX_RAW_SIZE: |
|
0 commit comments