Skip to content

Commit 4bc9bcc

Browse files
authored
Merge pull request #99 from krishnan05/fix/analytics-lint-empty-catch
fix: avoid empty catch blocks in analytics
2 parents 74e8a6a + 53bf2c1 commit 4bc9bcc

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/social-share-button.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,18 @@ class SocialShareButton {
705705
: this.options.container;
706706
}
707707

708+
/**
709+
* Logs analytics warnings only when debug mode is enabled.
710+
* @param {string} message - Description of the failed analytics path.
711+
* @param {Error} err - The caught error instance.
712+
*/
713+
_debugWarn(message, err) {
714+
// _debugWarn: emit analytics warnings only in debug mode for visibility.
715+
if (!this.options.debug) return;
716+
// eslint-disable-next-line no-console
717+
console.warn("[SocialShareButton Analytics]", message, err);
718+
}
719+
708720
/**
709721
* Emits an analytics event through all configured delivery paths.
710722
*
@@ -763,14 +775,18 @@ class SocialShareButton {
763775
});
764776
const el = this._getContainer();
765777
(el || document).dispatchEvent(domEvent);
766-
} catch (_) {}
778+
} catch (err) {
779+
this._debugWarn("DOM event dispatch failed", err);
780+
}
767781
}
768782

769783
// Path 2 — onAnalytics callback (direct, single-consumer hook)
770784
if (typeof this.options.onAnalytics === "function") {
771785
try {
772786
this.options.onAnalytics(payload);
773-
} catch (_) {}
787+
} catch (err) {
788+
this._debugWarn("onAnalytics callback failed", err);
789+
}
774790
}
775791

776792
// Path 3 — plugin / adapter registry (supports multiple simultaneous consumers)
@@ -779,7 +795,9 @@ class SocialShareButton {
779795
if (plugin && typeof plugin.track === "function") {
780796
try {
781797
plugin.track(payload);
782-
} catch (_) {}
798+
} catch (err) {
799+
this._debugWarn("plugin.track() failed", err);
800+
}
783801
}
784802
}
785803
}

0 commit comments

Comments
 (0)