Skip to content

fix: add debug-conditional console.warn to _emit() catch blocks for analytics delivery failures#93

Closed
harsh-791 wants to merge 1 commit intoAOSSIE-Org:mainfrom
harsh-791:Issue-92
Closed

fix: add debug-conditional console.warn to _emit() catch blocks for analytics delivery failures#93
harsh-791 wants to merge 1 commit intoAOSSIE-Org:mainfrom
harsh-791:Issue-92

Conversation

@harsh-791
Copy link

@harsh-791 harsh-791 commented Mar 12, 2026

Addressed Issues:

Fixes #92

Screenshots/Recordings:

No UI changes — this fix is purely in the JS logic layer. No screenshots applicable.

Additional Notes:

Added _emit() method to src/social-share-button.js with three analytics delivery paths (DOM CustomEvent dispatch, onAnalytics callback, analyticsPlugins loop), each wrapped in a try/catch. When debug: true is set on the instance, failed delivery paths emit a console.warn with context. When debug: false (default), behaviour is unchanged — failures remain silent and non-fatal so the core share action is never blocked.

Three new constructor options introduced:

  • debug (boolean, default false)
  • onAnalytics (function, default null)
  • analyticsPlugins (array, default [])

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • New Features
    • Social sharing analytics now include optional debug logging to surface delivery issues.
  • Bug Fixes
    • Made analytics delivery paths more resilient: failures in event dispatch, callback execution, or plugin tracking no longer break the flow and will emit debug warnings when enabled.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: dfc0a653-1cce-466b-89aa-a8c2d3d3c1b6

📥 Commits

Reviewing files that changed from the base of the PR and between e9abc8f and 7bfcb82.

📒 Files selected for processing (1)
  • src/social-share-button.js

Walkthrough

Updated _emit() in src/social-share-button.js to add guarded debug logging in three analytics delivery paths (CustomEvent dispatch, onAnalytics callback, and analyticsPlugins loop) so exceptions are logged via console.warn when debug is enabled; no public signatures changed.

Changes

Cohort / File(s) Summary
Analytics emission update
src/social-share-button.js
Added guarded debug logging to three previously-empty catch blocks inside _emit() to warn on failures from DOM CustomEvent dispatch, the onAnalytics callback, and individual analyticsPlugins.track() calls when debug is true. No API/signature changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Typescript Lang

Poem

🐰 I thumped my paw and gave a shout,
Errors now whisper, not snuffed out.
Events hop out, plugins take stage,
Debug lights guide the rabbit's sage,
Sharing sings without a pout.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding debug-conditional console.warn statements to empty catch blocks in the _emit() method for analytics delivery failures.
Linked Issues check ✅ Passed The PR fully addresses all requirements from issue #92: console.warn logging added to catch blocks for DOM CustomEvent dispatch, onAnalytics callback, and analyticsPlugins loop, all guarded by debug flag.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing debug-conditional error logging in _emit() catch blocks as specified in issue #92; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can generate walkthrough in a markdown collapsible section to save space.

Enable the reviews.collapse_walkthrough setting to generate walkthrough in a markdown collapsible section.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/social-share-button.js`:
- Around line 431-439: Add a defensive guard before iterating over
analyticsPlugins: verify that this.options.analyticsPlugins is an array (e.g.,
with Array.isArray) or default to an empty array, then iterate that safe value
instead of calling forEach directly on this.options.analyticsPlugins; update the
code around the block that calls plugin(eventName, data) so it skips iteration
when analyticsPlugins is null/undefined/non-array while preserving the existing
try/catch and debug console.warn behavior.
- Around line 412-440: Add minimal inline comments inside the _emit(eventName,
data) method describing the three logical delivery paths: a short comment above
the CustomEvent dispatch indicating it's broadcasting a DOM event with detail
payload, a comment above the onAnalytics invocation noting it's calling an
optional user-provided analytics callback, and a comment above the
this.options.analyticsPlugins.forEach loop stating it's invoking any configured
analytics plugins; keep comments concise and non-verbose and place them
immediately before the corresponding try blocks (referencing _emit,
this.options.onAnalytics, and this.options.analyticsPlugins).
- Around line 412-419: The _emit method calls document.dispatchEvent without
guarding for server-side rendering; update _emit to first check for the
existence of the global document (e.g., if (typeof document === "undefined")
return;) before creating/dispatching the CustomEvent, and keep the existing
try/catch & debug logging (this.options.debug) intact so browser behavior is
unchanged while avoiding crashes in SSR environments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3b7cb274-45f2-4abf-bde0-c1e2ecf6be89

📥 Commits

Reviewing files that changed from the base of the PR and between 9e7e113 and e9abc8f.

📒 Files selected for processing (1)
  • src/social-share-button.js

@kpj2006
Copy link
Contributor

kpj2006 commented Mar 20, 2026

alredy fixed by #99

@kpj2006 kpj2006 closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace empty catch blocks in _emit() with debug-conditional warnings

2 participants