Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow handled errors to be processed #2059

Merged

Conversation

saikumarrs
Copy link
Member

@saikumarrs saikumarrs commented Feb 24, 2025

PR Description

I've allowed handled errors to be processed even if they do not seem to be originated from the SDK. Especially, this is helpful for reporting and logging handled errors from the core SDK in the case of NPM installations.

Linear task (optional)

https://linear.app/rudderstack/issue/SDK-3011/unsuppress-handled-errors-for-npm-installations

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling to ensure that errors are consistently logged and reported for improved diagnostic tracking and system stability.
  • Tests
    • Updated test coverage to confirm that all handled errors, regardless of origin, are now correctly captured and reported.

@saikumarrs saikumarrs self-assigned this Feb 24, 2025
@saikumarrs saikumarrs requested a review from a team as a code owner February 24, 2025 04:42
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

This PR modifies the error handling logic in the analytics-js package. The test case for the ErrorHandler class has been updated to verify that errors—even those not originating from the SDK—are reported and logged. Correspondingly, the implementation in the ErrorHandler class has been adjusted to change its filtering conditions by adding an extra check for handled exceptions. The control flow now actively processes and reports errors that were previously ignored. There are no changes to exported or public entities.

Changes

File Change Summary
packages/analytics-js/tests/.../ErrorHandler.test.ts Renamed test case; now expects errors not from the SDK to be reported and logged; asserts that defaultHttpClient.getAsyncData is called once.
packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts Modified onError method; added a condition to check errorType !== ErrorType.HANDLEDEXCEPTION, updating the filtering logic and clarifying comments for NPM contexts.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ErrorHandler
    participant HTTPClient as DefaultHttpClient
    participant Console

    Client->>ErrorHandler: Trigger error
    ErrorHandler-->>ErrorHandler: Evaluate error type and origin
    alt Error qualifies for reporting (including handled exceptions)
        ErrorHandler->>HTTPClient: Call getAsyncData() to report error
        ErrorHandler->>Console: Log error details
    else Error should be ignored
        ErrorHandler-->>Client: Discard error
    end
Loading

Possibly related PRs

Suggested reviewers

  • ChryssaAliferi
  • koladilip

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed4db5b and 21a2838.

📒 Files selected for processing (2)
  • packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts (1 hunks)
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (1)
Learnt from: saikumarrs
PR: rudderlabs/rudder-sdk-js#1907
File: packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts:172-174
Timestamp: 2024-11-12T15:14:23.319Z
Learning: The function `onError` in `packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts` is acceptable as currently implemented, and refactoring suggestions are not required unless necessary.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Security and code quality checks
  • GitHub Check: Bundle size checks
🔇 Additional comments (3)
packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (2)

78-79: LGTM! Clear documentation improvement.

The updated comment provides valuable clarity about error handling behavior in NPM installations.


80-84:

❓ Verification inconclusive

Verify the impact of relaxed error filtering.

The modified condition now allows handled exceptions to be processed even when they're not SDK-originated. While this aligns with the PR objective, we should ensure this doesn't lead to excessive error reporting.

Let's verify the potential impact:


🏁 Script executed:

#!/bin/bash
# Search for all error handling patterns to understand the scope
ast-grep --pattern 'errorType === ErrorType.HANDLEDEXCEPTION'

# Look for existing error handling patterns
rg -l 'onError\(' --type ts

Length of output: 242


Action Required: Verify the Impact of Relaxed Error Filtering

The change in the condition at packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (lines 80–84) now permits handled exceptions to be processed even when they’re not SDK-originated. While this meets the PR’s objective, we need to ensure that this alteration does not inadvertently lead to excessive error reporting.

  • Observation: Initial searches (using ast-grep and rg) did not return any files, likely due to restrictive filtering options or file type constraints.
  • Next Steps:
    • Please re-run the search with adjusted filters or the --debug flag to confirm that there aren’t unexpected usages of errorType === ErrorType.HANDLEDEXCEPTION or related error handling patterns elsewhere in the codebase.
    • For example, consider running:
      rg --debug -l 'errorType\s*===\s*ErrorType\.HANDLEDEXCEPTION' .
      rg --debug -l 'onError\(' .
    • A manual verification might be required if automated scripts continue to produce no results.

Please verify that the broader error reporting remains controlled with this relaxed error filtering.

packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts (1)

120-132: LGTM! Comprehensive test coverage for the new behavior.

The test case has been properly updated to verify that:

  1. Handled errors are now processed regardless of origin
  2. Errors are reported to metrics service
  3. Errors are logged to console
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.42%. Comparing base (ed4db5b) to head (21a2838).
Report is 3 commits behind head on hotfix/unsuppress-npm-errors.

Additional details and impacted files
@@                      Coverage Diff                      @@
##           hotfix/unsuppress-npm-errors    #2059   +/-   ##
=============================================================
  Coverage                         61.41%   61.42%           
=============================================================
  Files                               478      478           
  Lines                             16404    16405    +1     
  Branches                           3232     3235    +3     
=============================================================
+ Hits                              10075    10076    +1     
+ Misses                             5122     5113    -9     
- Partials                           1207     1216    +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@saikumarrs
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Legacy - CDN 13.66 KB 13.66 KB (0%) 14 KB
Plugins - Modern - CDN 5.64 KB 5.64 KB (0%) 6 KB
Common - No bundling 17.93 KB 17.93 KB (0%) 18.4 KB
Load Snippet 765 B 765 B (0%) 1 KB
Core (v1.1) - NPM (ESM) 30.16 KB 30.16 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.32 KB 30.32 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.23 KB 30.23 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.59 KB 29.59 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (CJS) 29.84 KB 29.84 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (UMD) 29.71 KB 29.71 KB (0%) 30.5 KB
Core (v1.1) - Legacy - CDN 32.03 KB 32.03 KB (0%) 32.5 KB
Core (v1.1) - Modern - CDN 30 KB 30 KB (0%) 32 KB
Service Worker - Legacy - NPM (ESM) 30.54 KB 30.54 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.85 KB 30.85 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.69 KB 30.69 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.73 KB 25.73 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 26 KB 26 KB (0%) 26.5 KB
Service Worker - Modern - NPM (UMD) 25.75 KB 25.75 KB (0%) 26 KB
Core - Legacy - NPM (ESM) 47.42 KB 47.42 KB (-0.01% ▼) 48 KB
Core - Legacy - NPM (CJS) 47.64 KB 47.65 KB (+0.04% ▲) 48 KB
Core - Legacy - NPM (UMD) 47.41 KB 47.44 KB (+0.06% ▲) 48 KB
Core - Legacy - CDN 47.53 KB 47.51 KB (-0.05% ▼) 47.6 KB
Core - Modern - NPM (ESM) 26.85 KB 26.87 KB (+0.08% ▲) 27 KB
Core - Modern - NPM (CJS) 27.06 KB 27.06 KB (+0.03% ▲) 27.1 KB
Core - Modern - NPM (UMD) 26.89 KB 26.93 KB (+0.15% ▲) 27 KB
Core - Modern - CDN 27.13 KB 27.1 KB (-0.1% ▼) 27.5 KB
Core (Bundled) - Legacy - NPM (ESM) 47.42 KB 47.42 KB (-0.01% ▼) 48 KB
Core (Bundled) - Legacy - NPM (CJS) 47.67 KB 47.64 KB (-0.06% ▼) 48 KB
Core (Bundled) - Legacy - NPM (UMD) 47.41 KB 47.44 KB (+0.06% ▲) 48 KB
Core (Bundled) - Modern - NPM (ESM) 38.57 KB 38.61 KB (+0.09% ▲) 39 KB
Core (Bundled) - Modern - NPM (CJS) 38.88 KB 38.8 KB (-0.21% ▼) 39 KB
Core (Bundled) - Modern - NPM (UMD) 38.56 KB 38.61 KB (+0.13% ▲) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 47.32 KB 47.36 KB (+0.08% ▲) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 47.59 KB 47.6 KB (+0.02% ▲) 48 KB
Core (Content Script) - Legacy - NPM (UMD) 47.38 KB 47.36 KB (-0.04% ▼) 48 KB
Core (Content Script) - Modern - NPM (ESM) 38.5 KB 38.5 KB (0%) 39 KB
Core (Content Script) - Modern - NPM (CJS) 38.78 KB 38.78 KB (-0.02% ▼) 39 KB
Core (Content Script) - Modern - NPM (UMD) 38.54 KB 38.56 KB (+0.04% ▲) 39 KB
All Integrations - Legacy - CDN 94.94 KB 94.94 KB (0%) 95.3 KB
All Integrations - Modern - CDN 90.5 KB 90.5 KB (0%) 91 KB

@saikumarrs saikumarrs merged commit 218fd4e into hotfix/unsuppress-npm-errors Feb 24, 2025
12 checks passed
@saikumarrs saikumarrs deleted the fix.unsuppress-hotfix-errors-sdk-3011 branch February 24, 2025 08:10
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.

3 participants