diff --git a/app/configurator/alerts.go b/app/configurator/alerts.go index 30e03e3..5fd5ba6 100644 --- a/app/configurator/alerts.go +++ b/app/configurator/alerts.go @@ -2,6 +2,7 @@ package configurator import ( "darkbot/app/configurator/models" + "darkbot/app/settings/logus" "darkbot/app/settings/types" ) @@ -120,7 +121,8 @@ func (c IConfiguratorAlertThreshold[T]) Unset(channelID types.DiscordChannelID) func (c IConfiguratorAlertThreshold[T]) Status(channelID types.DiscordChannelID) (int, error) { var obj T - result := c.db.Where("channel_id = ?", channelID).First(&obj) + result := c.db.Where("channel_id = ?", channelID).Limit(1).Find(&obj) + if result.Error != nil { return 0, result.Error } @@ -155,7 +157,7 @@ func (c IConfiguratorAlertBool[T]) Disable(channelID types.DiscordChannelID) err func (c IConfiguratorAlertBool[T]) Status(channelID types.DiscordChannelID) (bool, error) { obj := T{} - result := c.db.Where("channel_id = ?", channelID).First(&obj) + result := c.db.Where("channel_id = ?", channelID).Limit(1).Find(&obj) return result.Error == nil && result.RowsAffected == 1, result.Error } @@ -175,13 +177,14 @@ func (c IConfiguratorAlertString[T]) Set(channelID types.DiscordChannelID, value func (c IConfiguratorAlertString[T]) Unset(channelID types.DiscordChannelID) error { objs := []T{} result := c.db.Unscoped().Where("channel_id = ?", channelID).Find(&objs) + logus.CheckWarn(result.Error, "attempted to unset with errors", logus.GormResult(result)) result = c.db.Unscoped().Delete(&objs) return result.Error } func (c IConfiguratorAlertString[T]) Status(channelID types.DiscordChannelID) (types.PingMessage, error) { var obj T - result := c.db.Where("channel_id = ?", channelID).First(&obj) + result := c.db.Where("channel_id = ?", channelID).Limit(1).Find(&obj) if result.Error != nil { return "", result.Error } diff --git a/app/configurator/errors.go b/app/configurator/errors.go index 64d2ce7..8f650ca 100644 --- a/app/configurator/errors.go +++ b/app/configurator/errors.go @@ -9,7 +9,7 @@ type ErrorZeroAffectedRows struct { } func (z ErrorZeroAffectedRows) Error() string { - return "Zero affected rows. Expected more." + z.ExtraMsg + return "Zero affected rows. not found records. Expected more." + z.ExtraMsg } /////////////////////