From 8e0defe3ca6c8008b62c820ffccaf8be00e0b829 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 21 Jul 2022 22:27:30 +0200 Subject: [PATCH] more context on failure --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index a9bd98f..bab0971 100644 --- a/main.py +++ b/main.py @@ -204,6 +204,12 @@ async def main(): TASK_AUTHORS.setdefault(task_author, 1) TASK_AUTHORS[task_author] -= 1 + def _err(_task, err): + term = _task.term + if len(term) >= 12: + term = _task.term[:12] + ".." + return bot.send("PRIVMSG", target=_task.channel, message=f"{_task.author}: Error \"{term}\"; {err}") + # main loop while True: now = datetime.now() @@ -213,14 +219,14 @@ async def main(): try: images = await task.get_images() except Exception as ex: - bot.send("PRIVMSG", target=task.channel, message=f"could not fetch images: {ex}") + _err(task, err=f"Fetch: {ex}") _lower_author_task_count(task.author) continue try: image = await task.process_images(images) except Exception as ex: - bot.send("PRIVMSG", target=task.channel, message=f"could not process images: {ex}") + _err(task, err=f"Process: {ex}") _lower_author_task_count(task.author) continue @@ -232,14 +238,14 @@ async def main(): try: url = await task.post_image(image_bytes) except Exception as ex: - bot.send("PRIVMSG", target=task.channel, message=str(ex)) + _err(task, err=f"uguu upload: {ex}") _lower_author_task_count(task.author) continue _lower_author_task_count(task.author) completed_secs = (datetime.now() - now).total_seconds() - bot.send("PRIVMSG", target=task.channel, message=f"{url} \"{task.term}\" ({completed_secs}sec, {task.author}) ") + bot.send("PRIVMSG", target=task.channel, message=f"{url} \"{task.term}\" (total: {completed_secs}s, {task.author}) ") await asyncio.sleep(10) loop = asyncio.get_event_loop()