From db8c18f6eb983ac0f2c6600f7884e234ba58d0c3 Mon Sep 17 00:00:00 2001 From: Javier Ferrer Date: Wed, 5 Jul 2023 14:30:09 +0200 Subject: [PATCH] Improve error checking code and fix sql script --- changelog/unreleased/notifications-changes.md | 3 +++ .../services/notifications/notifications.go | 15 +++++++-------- pkg/notification/db_changes.sql | 3 ++- pkg/notification/notification.go | 4 ++-- pkg/notification/template/template.go | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 changelog/unreleased/notifications-changes.md diff --git a/changelog/unreleased/notifications-changes.md b/changelog/unreleased/notifications-changes.md new file mode 100644 index 00000000000..49e05ae82bd --- /dev/null +++ b/changelog/unreleased/notifications-changes.md @@ -0,0 +1,3 @@ +Change: Clean up notifications error checking code, fix sql creation script + +https://github.com/cs3org/reva/pull/4041 diff --git a/internal/serverless/services/notifications/notifications.go b/internal/serverless/services/notifications/notifications.go index b51b163fd4c..c8559b2c825 100644 --- a/internal/serverless/services/notifications/notifications.go +++ b/internal/serverless/services/notifications/notifications.go @@ -217,14 +217,13 @@ func (s *svc) handleMsgTemplate(msg []byte) { name, err := s.templates.Put(msg, s.handlers) if err != nil { - s.log.Error().Err(err).Msgf("template registration failed %v", err) + s.log.Error().Err(err).Msg("template registration failed") // If a template file was not found, delete that template from the registry altogether, // this way we ensure templates that are deleted from the config are deleted from the // store too. - wrappedErr := errors.Unwrap(errors.Unwrap(err)) - _, isFileNotFoundError := wrappedErr.(*template.FileNotFoundError) - if isFileNotFoundError && name != "" { + var e *template.FileNotFoundError + if errors.As(err, &e) && name != "" { err := s.kv.Purge(name) if err != nil { s.log.Error().Err(err).Msgf("deletion of template %s from store failed", name) @@ -270,8 +269,8 @@ func (s *svc) handleMsgUnregisterNotification(msg *nats.Msg) { err := s.nm.DeleteNotification(ref) if err != nil { - _, isNotFoundError := err.(*notification.NotFoundError) - if isNotFoundError { + var e *notification.NotFoundError + if errors.As(err, &e) { s.log.Debug().Msgf("a notification with ref %s does not exist", ref) } else { s.log.Error().Err(err).Msgf("notification unregister failed") @@ -318,8 +317,8 @@ func (s *svc) handleMsgTrigger(msg *nats.Msg) { if notif == nil { notif, err = s.nm.GetNotification(tr.Ref) if err != nil { - _, isNotFoundError := err.(*notification.NotFoundError) - if isNotFoundError { + var e *notification.NotFoundError + if errors.As(err, &e) { s.log.Debug().Msgf("trigger %s does not have a notification attached", tr.Ref) return } diff --git a/pkg/notification/db_changes.sql b/pkg/notification/db_changes.sql index a240b633007..a5d635b7793 100644 --- a/pkg/notification/db_changes.sql +++ b/pkg/notification/db_changes.sql @@ -41,11 +41,12 @@ COMMIT; CREATE INDEX `cbox_notifications_ix0` ON `cbox_notifications` (`ref`); CREATE INDEX `cbox_notification_recipients_ix0` ON `cbox_notification_recipients` (`notification_id`); -CREATE INDEX `cbox_notification_recipients_ix1` ON `cbox_notification_recipients` (`user_name`); +CREATE INDEX `cbox_notification_recipients_ix1` ON `cbox_notification_recipients` (`recipient`); -- changes for added notifications on oc shares ALTER TABLE cernboxngcopy.oc_share ADD notify_uploads BOOL DEFAULT false; +ALTER TABLE cernboxngcopy.oc_share ADD notify_uploads_extra_recipients VARCHAR(2048); UPDATE cernboxngcopy.oc_share SET notify_uploads = false; diff --git a/pkg/notification/notification.go b/pkg/notification/notification.go index fdf615f3699..b7c2d502571 100644 --- a/pkg/notification/notification.go +++ b/pkg/notification/notification.go @@ -55,12 +55,12 @@ type InvalidNotificationError struct { } // Error returns the string error msg for NotFoundError. -func (n *NotFoundError) Error() string { +func (n NotFoundError) Error() string { return fmt.Sprintf("notification %s not found", n.Ref) } // Error returns the string error msg for InvalidNotificationError. -func (i *InvalidNotificationError) Error() string { +func (i InvalidNotificationError) Error() string { return i.Msg } diff --git a/pkg/notification/template/template.go b/pkg/notification/template/template.go index 39d5fc0c189..d1ad5f85ffb 100644 --- a/pkg/notification/template/template.go +++ b/pkg/notification/template/template.go @@ -60,7 +60,7 @@ type FileNotFoundError struct { } // Error returns the string error msg for FileNotFoundError. -func (t *FileNotFoundError) Error() string { +func (t FileNotFoundError) Error() string { return fmt.Sprintf("template file %s not found", t.TemplateFileName) }