Skip to content

Commit

Permalink
Revert "Revert "feat: add error handling to all public apis (#1907)""
Browse files Browse the repository at this point in the history
This reverts commit ef1a977.
  • Loading branch information
saikumarrs committed Nov 18, 2024
1 parent 4a9bd24 commit 4b5aa80
Show file tree
Hide file tree
Showing 15 changed files with 993 additions and 430 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -171,7 +171,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down Expand Up @@ -205,7 +205,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -221,7 +221,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down Expand Up @@ -255,7 +255,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -271,7 +271,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-sanity-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Deployment: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Deployment: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -170,7 +170,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -249,7 +249,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>",
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
Expand All @@ -133,7 +133,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S07CCQ05F2T>"
"text": "*<${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
Expand Down
18 changes: 9 additions & 9 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
* @rudderlabs/js-sdk

/packages/analytics-js-integrations/src/ @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/__fixtures__/ @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/__tests__/ @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/__mocks__/ @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/README.md @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/.size-limit.js @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-integrations/src/ @rudderlabs/integrations
/packages/analytics-js-integrations/__fixtures__/ @rudderlabs/integrations
/packages/analytics-js-integrations/__tests__/ @rudderlabs/integrations
/packages/analytics-js-integrations/__mocks__/ @rudderlabs/integrations
/packages/analytics-js-integrations/README.md @rudderlabs/integrations
/packages/analytics-js-integrations/.size-limit.js @rudderlabs/integrations

/packages/analytics-js-common/src/constants/integrations/ @rudderlabs/js-sdk-dm-intg-eng
/assets/integrations/AdobeAnalytics/ @rudderlabs/js-sdk-dm-intg-eng
/examples/integrations/ @rudderlabs/js-sdk-dm-intg-eng
/packages/analytics-js-common/src/constants/integrations/ @rudderlabs/integrations
/assets/integrations/AdobeAnalytics/ @rudderlabs/integrations
/examples/integrations/ @rudderlabs/integrations
18 changes: 18 additions & 0 deletions packages/analytics-js-common/__tests__/utilities/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { dispatchErrorEvent } from '../../src/utilities/errors';

describe('Errors - utilities', () => {
describe('dispatchErrorEvent', () => {
it('should dispatch an error event', () => {
const dispatchEvent = jest.fn();
const originalDispatchEvent = globalThis.dispatchEvent;

globalThis.dispatchEvent = dispatchEvent;
const error = new Error('Test error');
dispatchErrorEvent(error);
expect(dispatchEvent).toHaveBeenCalledWith(new ErrorEvent('error', { error }));

// Cleanup
globalThis.dispatchEvent = originalDispatchEvent;
});
});
});
4 changes: 2 additions & 2 deletions packages/analytics-js-common/src/constants/loggerContexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LOAD_CONFIGURATION = 'LoadConfiguration';
const EVENT_REPOSITORY = 'EventRepository';
const EXTERNAL_SRC_LOADER = 'ExternalSrcLoader';
const HTTP_CLIENT = 'HttpClient';
const RS_APP = 'RudderStackApplication';
const RSA = 'RudderStackAnalytics';
const ANALYTICS_CORE = 'AnalyticsCore';

export {
Expand All @@ -28,6 +28,6 @@ export {
EVENT_REPOSITORY,
EXTERNAL_SRC_LOADER,
HTTP_CLIENT,
RS_APP,
RSA,
ANALYTICS_CORE,
};
2 changes: 1 addition & 1 deletion packages/analytics-js-common/src/types/ApiObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export type ApiObject = {
| ApiObject
| null
| Date
| (string | number | boolean | null | Date | ApiObject)[]
| (string | number | boolean | null | Date | ApiObject | undefined)[]
| undefined;
};
4 changes: 2 additions & 2 deletions packages/analytics-js-common/src/types/IRudderAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface IRudderAnalytics<T = any> {
/**
* Get the instance of Analytics that is set as default
*/
getAnalyticsInstance(writeKey?: string): T;
getAnalyticsInstance(writeKey?: string): T | undefined;

/**
* Trigger load event in buffer queue if exists
Expand Down Expand Up @@ -188,7 +188,7 @@ export interface IRudderAnalytics<T = any> {
/**
* To fetch the current sessionId
*/
getSessionId(): Nullable<number>;
getSessionId(): Nullable<number> | undefined;

/**
* To provide consent
Expand Down
11 changes: 10 additions & 1 deletion packages/analytics-js-common/src/utilities/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isTypeOfError } from './checks';
import { stringifyData } from './json';

const MANUAL_ERROR_IDENTIFIER = '[MANUAL ERROR]';

/**
* Get mutated error with issue prepended to error message
* @param err Original error
Expand All @@ -17,4 +19,11 @@ const getMutatedError = (err: any, issue: string): Error => {
return finalError;
};

export { getMutatedError };
const dispatchErrorEvent = (error: any) => {
if (isTypeOfError(error)) {
error.stack = `${error.stack ?? ''}\n${MANUAL_ERROR_IDENTIFIER}`;
}
(globalThis as typeof window).dispatchEvent(new ErrorEvent('error', { error }));
};

export { getMutatedError, dispatchErrorEvent, MANUAL_ERROR_IDENTIFIER };
Loading

0 comments on commit 4b5aa80

Please sign in to comment.