From f8c85b7c1e1343176004c52ea3e745053274639f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 8 Nov 2024 10:24:42 +0000 Subject: mod_bookmarks: Suppress error publishing empty legacy bookmarks w/ no PEP node It appears that when: 1) The user has no bookmarks 2 node in PEP 2) The client publishes an empty bookmark set to a legacy bookmarks location 3) mod_bookmarks will attempt to purge items from the non-existent node and log an error about the failure (item-not-found). This new code will suppress an item-not-found error from the purge operation in the empty-bookmarks case, and adds a log message for any other error (this is helpful because the existing log message confusingly says it was an error *publishing* to the node, which isn't always accurate). --- plugins/mod_bookmarks.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/mod_bookmarks.lua b/plugins/mod_bookmarks.lua index d67915f8..8fe3166a 100644 --- a/plugins/mod_bookmarks.lua +++ b/plugins/mod_bookmarks.lua @@ -167,10 +167,15 @@ local function publish_to_pep(jid, bookmarks, synchronise) if synchronise then -- If we set zero legacy bookmarks, purge the bookmarks 2 node. module:log("debug", "No bookmark in the set, purging instead."); - return service:purge(namespace, jid, true); - else - return true; + local ok, err = service:purge(namespace, jid, true); + -- It's okay if no node exists when purging, user has + -- no bookmarks anyway. + if not ok and err ~= "item-not-found" then + module:log("error", "Failed to clear items from bookmarks 2 node: %s", err); + return ok, err; + end end + return true; end -- Retrieve the current bookmarks2. -- cgit v1.2.3 From cf3403f90c03b000be389a196148fa4fe33cc8f1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 8 Nov 2024 10:28:29 +0000 Subject: mod_bookmarks: Clarify log messages on failure to sync to modern PEP bookmarks Previously the error messages said that it failed to "publish" to PEP, but sometimes a sync involves removing items, which can be confusing. The log was also the same for both legacy PEP and private XML bookmarks. Having different log messages makes it easier to debug the cause and location of any sync errors. --- plugins/mod_bookmarks.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_bookmarks.lua b/plugins/mod_bookmarks.lua index 8fe3166a..73ea5d41 100644 --- a/plugins/mod_bookmarks.lua +++ b/plugins/mod_bookmarks.lua @@ -314,7 +314,7 @@ local function on_publish_legacy_pep(event) local ok, err = publish_to_pep(session.full_jid, bookmarks, true); if not ok then - module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); + module:log("error", "Failed to sync legacy bookmarks to PEP for %s@%s: %s", session.username, session.host, err); session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); return true; end @@ -340,7 +340,7 @@ local function on_publish_private_xml(event) local ok, err = publish_to_pep(session.full_jid, bookmarks, true); if not ok then - module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); + module:log("error", "Failed to sync private XML bookmarks to PEP for %s@%s: %s", session.username, session.host, err); session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); return true; end -- cgit v1.2.3