mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[FIX] LilyPond mode no longer crashes on bad input
This commit is contained in:
parent
010bd2634b
commit
3ebc41fddb
2 changed files with 15 additions and 4 deletions
|
@ -17,7 +17,10 @@ def render(user: str, source: str, png: bool = True) -> str:
|
|||
tmp.write(bytes(fmt, encoding="utf8"))
|
||||
tmp.close()
|
||||
if png:
|
||||
subprocess.run(["lilypond", "-d", "preview", "--png", "-dresolution=500", tmp.name], cwd="/tmp")
|
||||
ret = subprocess.run(["lilypond", "-d", "preview", "--png", "-dresolution=500", tmp.name], cwd="/tmp", capture_output=True)
|
||||
if ret.returncode != 0:
|
||||
raise FileNotFoundError(ret.stderr.decode())
|
||||
|
||||
return tmp.name + ".preview.png"
|
||||
|
||||
subprocess.run(["lilypond", "-d", "preview", "--svg", tmp.name], cwd="/tmp")
|
||||
|
|
14
routes.py
14
routes.py
|
@ -16,7 +16,7 @@ async def route_help(r: Router, client: Client, room: str, event: RoomMessageTex
|
|||
|
||||
|
||||
async def route_delete(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
|
||||
if len(args) == 1:
|
||||
if len(args) == 1:
|
||||
import utils
|
||||
import os
|
||||
|
||||
|
@ -35,5 +35,13 @@ async def route_lshow(router: Router, client: Client, room: str, event: RoomMess
|
|||
import lilypond
|
||||
import utils
|
||||
if len(args) == 1:
|
||||
file = lilypond.render("", args[0])
|
||||
await utils.send_png(room, file)
|
||||
try:
|
||||
file = lilypond.render("", args[0])
|
||||
await utils.send_png(room, file)
|
||||
except FileNotFoundError as e:
|
||||
content = {
|
||||
"msgtype": "m.text",
|
||||
"body": f"Couldn't parse LilyPond correctly.\n```{e.args[0]}\n```",
|
||||
"formatted_body": f"Couldn't parse LilyPond correctly.<br><code><pre>{e.args[0]}</pre></code>",
|
||||
}
|
||||
await client.room_send(room, message_type="m.room.message", content=content)
|
||||
|
|
Loading…
Add table
Reference in a new issue