diff options
| author | 2022-03-13 07:39:24 +0530 | |
|---|---|---|
| committer | 2022-03-13 02:09:24 +0000 | |
| commit | d35e49cdb0d68e808d723c15d0f6cb82589be036 (patch) | |
| tree | 9abf5967796f81c53f0d0518a3cc4d8eda80db73 /bot/exts | |
| parent | truncate output. (#1041) (diff) | |
Handle Missing Logs in Latex API Response (#1036)
Co-authored-by: Xithrius <[email protected]>
Diffstat (limited to 'bot/exts')
| -rw-r--r-- | bot/exts/fun/latex.py | 15 | 
1 files changed, 9 insertions, 6 deletions
diff --git a/bot/exts/fun/latex.py b/bot/exts/fun/latex.py index 1dc9c2e5..d43ec8c4 100644 --- a/bot/exts/fun/latex.py +++ b/bot/exts/fun/latex.py @@ -56,7 +56,7 @@ def _process_image(data: bytes, out_file: BinaryIO) -> None:  class InvalidLatexError(Exception):      """Represents an error caused by invalid latex.""" -    def __init__(self, logs: str): +    def __init__(self, logs: Optional[str]):          super().__init__(logs)          self.logs = logs @@ -73,7 +73,7 @@ class Latex(commands.Cog):          async with self.bot.http_session.post(LATEX_API_URL, data=payload, raise_for_status=True) as response:              response_json = await response.json()          if response_json["status"] != "success": -            raise InvalidLatexError(logs=response_json["log"]) +            raise InvalidLatexError(logs=response_json.get("log"))          async with self.bot.http_session.get(              f"{LATEX_API_URL}/{response_json['filename']}",              raise_for_status=True @@ -110,12 +110,15 @@ class Latex(commands.Cog):                      with open(image_path, "wb") as out_file:                          await self._generate_image(TEMPLATE.substitute(text=query), out_file)                  except InvalidLatexError as err: -                    logs_paste_url = await self._upload_to_pastebin(err.logs)                      embed = discord.Embed(title="Failed to render input.") -                    if logs_paste_url: -                        embed.description = f"[View Logs]({logs_paste_url})" +                    if err.logs is None: +                        embed.description = "No logs available."                      else: -                        embed.description = "Couldn't upload logs." +                        logs_paste_url = await self._upload_to_pastebin(err.logs) +                        if logs_paste_url: +                            embed.description = f"[View Logs]({logs_paste_url})" +                        else: +                            embed.description = "Couldn't upload logs."                      await ctx.send(embed=embed)                      image_path.unlink()                      return  |