From e268345c10052ce0614c64f3d366ca2c9f24fcad Mon Sep 17 00:00:00 2001 From: James Gerity Date: Fri, 5 Aug 2022 21:57:27 -0400 Subject: [PATCH] seen: catch database write errors (fixes #2305) --- sopel/modules/seen.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sopel/modules/seen.py b/sopel/modules/seen.py index 71605ab9eb..932eb010fb 100644 --- a/sopel/modules/seen.py +++ b/sopel/modules/seen.py @@ -9,10 +9,17 @@ """ from __future__ import annotations +import logging + +from sqlalchemy.exc import SQLAlchemyError + from sopel import plugin from sopel.tools.time import seconds_to_human +logger = logging.getLogger(__name__) + + @plugin.command('seen') @plugin.output_prefix('[seen] ') def seen(bot, trigger): @@ -63,9 +70,12 @@ def seen(bot, trigger): @plugin.require_chanmsg def note(bot, trigger): nick = trigger.nick - # as of Sopel 8, `trigger.time` is Aware, meaning we should store its value - # for timezone safety when comparing it later - bot.db.set_nick_value(nick, 'seen_timestamp', trigger.time.timestamp()) - bot.db.set_nick_value(nick, 'seen_channel', trigger.sender) - bot.db.set_nick_value(nick, 'seen_message', trigger) - bot.db.set_nick_value(nick, 'seen_action', trigger.ctcp is not None) + try: + # as of Sopel 8, `trigger.time` is Aware, meaning we should store its value + # for timezone safety when comparing it later + bot.db.set_nick_value(nick, 'seen_timestamp', trigger.time.timestamp()) + bot.db.set_nick_value(nick, 'seen_channel', trigger.sender) + bot.db.set_nick_value(nick, 'seen_message', trigger) + bot.db.set_nick_value(nick, 'seen_action', trigger.ctcp is not None) + except SQLAlchemyError: + logger.exception("Database write failed")