mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[ADD] Show error logs when something bad occurs.
This commit is contained in:
parent
bf6f537d21
commit
2041487fa0
2 changed files with 14 additions and 7 deletions
6
latex.py
6
latex.py
|
@ -24,9 +24,9 @@ def render(user: str, source: str, png: bool = True) -> str:
|
|||
tmp.close()
|
||||
# Parse our templated file thru' LaTeX and dvipng.
|
||||
# TODO: Allow arbitrary DPI and foreground color.
|
||||
ret = subprocess.run(["latex", "-halt-on-error", tmp.name], cwd="/tmp").returncode
|
||||
if ret != 0:
|
||||
raise FileNotFoundError("DVI couldn't be built.")
|
||||
ret = subprocess.run(["latex", "-halt-on-error", tmp.name], cwd="/tmp", capture_output=True)
|
||||
if ret.returncode != 0:
|
||||
raise FileNotFoundError(ret.stdout.decode())
|
||||
|
||||
if png:
|
||||
print("PNG")
|
||||
|
|
15
main.py
15
main.py
|
@ -42,16 +42,23 @@ async def msg_cb(room: MatrixRoom, event: RoomMessageText) -> None:
|
|||
try:
|
||||
filename = latex.render("", event.body)
|
||||
await send_png(room, filename)
|
||||
except (FileNotFoundError, OSError):
|
||||
except FileNotFoundError as e:
|
||||
content = {
|
||||
"msgtype": "m.text",
|
||||
"body": "Couldn't parse LaTeX correctly."
|
||||
"body": f"Couldn't parse LaTeX correctly.\n```{e.args[0]}\n```",
|
||||
"formatted_body": f"Couldn't parse LaTeX correctly.<br><code><pre>{e.args[0]}</pre></code>",
|
||||
}
|
||||
|
||||
await client.room_send(room.room_id, message_type="m.room.message", content=content)
|
||||
except OSError:
|
||||
content = {
|
||||
"msgtype": "m.text",
|
||||
"body": "???",
|
||||
"formatted_body": "???"
|
||||
}
|
||||
|
||||
await client.room_send(room.room_id, message_type="m.room.message", content=content)
|
||||
# Our file callback.
|
||||
|
||||
|
||||
async def file_cb(room: MatrixRoom, event: RoomMessageFile) -> None:
|
||||
url = event.url
|
||||
filename = event.body
|
||||
|
|
Loading…
Add table
Reference in a new issue