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: filter non error type errors #1865

Merged
merged 4 commits into from
Sep 26, 2024

Conversation

MoumitaM
Copy link
Contributor

@MoumitaM MoumitaM commented Sep 26, 2024

PR Description

This PR fixes a scenario where we create new errors from error messages if the type of the error is not an error.

Linear task (optional)

Linear task link

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
    • Simplified the error normalization process by directly checking for Error instances, improving error handling.
    • Removed unnecessary properties from error configuration, streamlining the payload creation process.

These changes enhance the reliability and efficiency of error reporting within the application.

@MoumitaM MoumitaM requested a review from a team as a code owner September 26, 2024 11:41
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve simplifying the error reporting utilities by removing certain properties from configuration objects and eliminating the hasNecessaryFields function. The normaliseError function now only checks if an input is an instance of the Error class, logging a warning if it is not. Additionally, the payload creation process has been streamlined by removing unnecessary destructured variables, focusing on essential properties.

Changes

File Path Change Summary
packages/analytics-js-plugins/tests/errorReporting/utils.test.ts Removed tolerateNonErrors and errorFramesToSkip from expected configuration objects for various error types.
packages/analytics-js-plugins/src/errorReporting/event/event.ts Removed the hasNecessaryFields function; simplified logic in normaliseError function and modified stack trace handling.
packages/analytics-js-plugins/src/errorReporting/index.ts Simplified destructuring in getConfigForPayloadCreation and updated payload creation logic.
packages/analytics-js-plugins/src/errorReporting/utils.ts Removed tolerateNonErrors and errorFramesToSkip from returned configuration for specific error types.

Possibly related PRs

  • fix: auto session tracking #1856: The changes in this PR involve modifications to session tracking logic, which does not directly relate to the changes made in the main PR regarding error reporting utilities and configuration objects.

Suggested reviewers

  • saikumarrs

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ecbb6b4 and b21700f.

📒 Files selected for processing (1)
  • packages/analytics-js-plugins/tests/errorReporting/utils.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/analytics-js-plugins/tests/errorReporting/utils.test.ts

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 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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 26, 2024
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 56.85%. Comparing base (ed32560) to head (b21700f).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...s/analytics-js-plugins/src/errorReporting/index.ts 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1865      +/-   ##
===========================================
- Coverage    57.12%   56.85%   -0.28%     
===========================================
  Files          476      476              
  Lines        16231    16232       +1     
  Branches      3240     3241       +1     
===========================================
- Hits          9272     9228      -44     
- Misses        5726     5753      +27     
- Partials      1233     1251      +18     

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

Copy link
Member

@saikumarrs saikumarrs left a comment

Choose a reason for hiding this comment

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

We should also ignore errors without a stack trace (Ln 78).

Copy link

github-actions bot commented Sep 26, 2024

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.53 KB 1.53 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 - Legacy - CDN 15.96 KB 15.46 KB (-3.12% ▼) 16 KB
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Modern - CDN 7.19 KB 7.19 KB (0%) 7.5 KB
Common - No bundling 16.2 KB 16.2 KB (0%) 16.5 KB
Service Worker - Legacy - NPM (ESM) 30.42 KB 30.42 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.64 KB 30.64 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.42 KB 30.42 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.49 KB 25.49 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 25.76 KB 25.76 KB (0%) 26 KB
Service Worker - Modern - NPM (UMD) 25.5 KB 25.5 KB (0%) 26 KB
Core (v1.1) - NPM (ESM) 30 KB 30 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.14 KB 30.14 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.09 KB 30.09 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.58 KB 29.58 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (CJS) 29.7 KB 29.7 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (UMD) 29.64 KB 29.64 KB (0%) 30 KB
Core - Legacy - CDN 47.65 KB 47.31 KB (-0.7% ▼) 48 KB
Core - Modern - CDN 24.27 KB 24.27 KB (0%) 24.5 KB
Load Snippet 778 B 778 B (0%) 1 KB
Core - Legacy - NPM (ESM) 47.46 KB 47.24 KB (-0.45% ▼) 48 KB
Core - Legacy - NPM (CJS) 47.73 KB 47.47 KB (-0.56% ▼) 48 KB
Core - Legacy - NPM (UMD) 47.5 KB 47.25 KB (-0.53% ▼) 48 KB
Core - Modern - NPM (ESM) 24.01 KB 24.01 KB (0%) 24.5 KB
Core - Modern - NPM (CJS) 24.24 KB 24.24 KB (0%) 24.5 KB
Core - Modern - NPM (UMD) 24.03 KB 24.03 KB (0%) 24.5 KB
Core (Bundled) - Legacy - NPM (ESM) 47.46 KB 47.24 KB (-0.45% ▼) 48 KB
Core (Bundled) - Legacy - NPM (CJS) 47.78 KB 47.51 KB (-0.56% ▼) 48 KB
Core (Bundled) - Legacy - NPM (UMD) 47.5 KB 47.25 KB (-0.53% ▼) 48 KB
Core (Bundled) - Modern - NPM (ESM) 38.75 KB 38.55 KB (-0.51% ▼) 39 KB
Core (Bundled) - Modern - NPM (CJS) 39 KB 38.82 KB (-0.47% ▼) 39.5 KB
Core (Bundled) - Modern - NPM (UMD) 38.75 KB 38.59 KB (-0.41% ▼) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 47.01 KB 46.73 KB (-0.61% ▼) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 47.28 KB 46.98 KB (-0.62% ▼) 47.5 KB
Core (Content Script) - Legacy - NPM (UMD) 47.02 KB 46.74 KB (-0.6% ▼) 47.5 KB
Core (Content Script) - Modern - NPM (ESM) 38.25 KB 38.06 KB (-0.5% ▼) 38.5 KB
Core (Content Script) - Modern - NPM (CJS) 38.46 KB 38.35 KB (-0.31% ▼) 38.5 KB
Core (Content Script) - Modern - NPM (UMD) 38.27 KB 38.08 KB (-0.49% ▼) 38.5 KB
All Integrations - Legacy - CDN 94.36 KB 94.36 KB (0%) 95.3 KB
All Integrations - Modern - CDN 89.53 KB 89.53 KB (0%) 91 KB

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: 0

🧹 Outside diff range and nitpick comments (1)
packages/analytics-js-plugins/src/errorReporting/event/event.ts (1)

Line range hint 1-124: Consider additional improvements to error handling

While the current changes improve error filtering, consider the following suggestions for further optimization:

  1. Error Logging: The current implementation logs a warning when a non-error is received. Consider adding more detailed logging or telemetry to track the frequency and types of non-error objects being passed.

  2. Performance: The ErrorStackParser.parse() method is called for every error. For high-volume applications, this could potentially impact performance. Consider implementing a caching mechanism for parsed stack traces.

  3. Browser Compatibility: Ensure that the isError() function (imported from ./utils) is compatible with all targeted browsers, especially older versions of IE11 if that's still a requirement.

  4. Error Transformation: Consider adding a mechanism to transform non-standard error objects into standard Error objects, rather than discarding them entirely. This could help capture more meaningful error data in environments where custom error types are used.

Here's a sample implementation for error transformation:

function transformToError(maybeError: any): Error {
  if (isError(maybeError)) {
    return maybeError;
  }
  const errorMessage = typeof maybeError === 'string' ? maybeError : stringifyWithoutCircular(maybeError);
  return new Error(errorMessage);
}

// Then in normaliseError:
if (!isError(maybeError)) {
  logger?.warn(
    `${ERROR_REPORTING_PLUGIN}:: ${component} received a non-error: ${stringifyWithoutCircular(maybeError)}`,
  );
  error = transformToError(maybeError);
} else {
  error = maybeError;
}

This approach would allow you to capture more information from non-standard errors while still maintaining type safety.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between faf2e52 and 4c36bac.

📒 Files selected for processing (1)
  • packages/analytics-js-plugins/src/errorReporting/event/event.ts (1 hunks)
🔇 Additional comments (3)
packages/analytics-js-plugins/src/errorReporting/event/event.ts (3)

78-81: Approve changes in error handling logic

The modifications to the normaliseError function align well with the PR objectives. The function now effectively filters out non-error type errors and errors without stack traces. This simplification makes the code more robust and less prone to unexpected behavior.

Benefits of these changes:

  1. Only valid Error instances are processed, preventing the creation of erroneous error objects.
  2. Errors without stack traces are filtered out, addressing the issue mentioned in SDK-2284.
  3. The code is more straightforward and easier to maintain.

Line range hint 1-124: Summary of review and next steps

The changes in this file successfully address the PR objectives by improving error filtering in the normaliseError function. The modifications effectively handle non-error type errors and errors without stack traces, aligning with the goals outlined in the PR summary and the related Linear task (SDK-2284).

Next steps:

  1. Verify the impact of these changes on the overall error reporting process using the provided script.
  2. Consider implementing the suggested improvements for error transformation and logging.
  3. Ensure cross-browser compatibility, especially for IE11 as mentioned in the PR checklist.
  4. Run the sanity suite test cases locally to confirm no regressions have been introduced.
  5. Review the security checklist to ensure these changes don't introduce any vulnerabilities.

Once these steps are completed and any necessary adjustments are made, this PR should be ready for final review and merge.


78-81: Verify impact on error reporting process

While the changes improve error filtering, we should verify that this doesn't negatively impact the error reporting process.

Please run the following script to check for any potential issues:

Please review the results to ensure that the changes don't cause any unintended side effects in the error reporting process.

✅ Verification successful

Impact on Error Reporting Process Verified Successfully

The changes to error filtering do not negatively impact the error reporting process. All existing error handling and logging mechanisms remain intact.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential issues in error handling across the codebase

# Test 1: Check for uses of normaliseError function
echo "Checking uses of normaliseError function:"
rg "normaliseError\(" --type typescript

# Test 2: Check for any custom error handling that might be affected
echo "Checking for custom error handling:"
rg "new Error\(" --type typescript

# Test 3: Check for any error logging that might be affected
echo "Checking for error logging:"
rg "console\.error\(" --type typescript
rg "logger.*error\(" --type typescript

# Expected results:
# - No unexpected uses of normaliseError
# - No custom error handling that relies on non-Error objects
# - No error logging that might be affected by the changes

Length of output: 540


Script:

#!/bin/bash
# Description: Recheck potential issues in error handling across the codebase with corrected file type patterns

# Test 1: Check for uses of normaliseError function
echo "Checking uses of normaliseError function:"
rg "normaliseError\(" -g '*.ts*'

# Test 2: Check for any custom error handling that might be affected
echo "Checking for custom error handling:"
rg "new Error\(" -g '*.ts*'

# Test 3: Check for any error logging that might be affected
echo "Checking for error logging:"
rg "console\.error\(" -g '*.ts*'
rg "logger.*error\(" -g '*.ts*'

Length of output: 16722

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 26, 2024
@MoumitaM
Copy link
Contributor Author

@saikumarrs Addressed you comment

@MoumitaM MoumitaM requested a review from saikumarrs September 26, 2024 13:05
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4c36bac and ecbb6b4.

📒 Files selected for processing (4)
  • packages/analytics-js-plugins/tests/errorReporting/utils.test.ts (0 hunks)
  • packages/analytics-js-plugins/src/errorReporting/event/event.ts (3 hunks)
  • packages/analytics-js-plugins/src/errorReporting/index.ts (1 hunks)
  • packages/analytics-js-plugins/src/errorReporting/utils.ts (0 hunks)
💤 Files not reviewed due to no reviewable changes (2)
  • packages/analytics-js-plugins/tests/errorReporting/utils.test.ts
  • packages/analytics-js-plugins/src/errorReporting/utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/analytics-js-plugins/src/errorReporting/event/event.ts

Copy link

@MoumitaM MoumitaM merged commit 060f66c into develop Sep 26, 2024
11 checks passed
@MoumitaM MoumitaM deleted the fix/SDK-2284-filter-errors-without-stacktrace branch September 26, 2024 15:21
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
5 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 18, 2024
5 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 27, 2024
5 tasks
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.

2 participants