Skip to content

Commit d59ff29

Browse files
authored
chore: Replace deprecated error reporting service calls with Messenger.captureException (#7542)
## Explanation `error-reporting-service` is deprecated in favour of `Messenger.captureException`. There were a couple controllers still using it, which I've fixed in this pull request by replacing the usage of `ErrorReportingService:captureException` with `Messenger.captureException`. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Migrates error reporting to the new Messenger API and cleans up the deprecated dependency. > > - Replace calls to `ErrorReportingService:captureException` with optional `Messenger.captureException` across `multichain-account-service`, `network-controller`, and tests (e.g., `MultichainAccount{Service,Wallet,Group}.ts`, `SnapAccountProvider.ts`, `NetworkController.ts`, `GasFeeController.test.ts`) > - Remove `@metamask/error-reporting-service` from `package.json` dependencies and `yarn.lock`; update CHANGELOGs for affected packages > - Adjust messengers to expose `captureException` in tests/utilities and drop related delegated actions > - Update tests to spy on `captureException` instead of `messenger.call(...)`; fix types by removing `ErrorReportingService*` action from allowed actions > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 7d112ea. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 18a2ce0 commit d59ff29

20 files changed

+61
-144
lines changed

packages/eth-json-rpc-middleware/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
},
7070
"devDependencies": {
7171
"@metamask/auto-changelog": "^3.4.4",
72-
"@metamask/error-reporting-service": "^3.0.1",
7372
"@metamask/network-controller": "^27.1.0",
7473
"@ts-bridge/cli": "^0.6.4",
7574
"@types/deep-freeze-strict": "^1.1.0",

packages/gas-fee-controller/src/GasFeeController.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ const getRootMessenger = (): RootMessenger => {
6767
MessengerActions<NetworkControllerMessenger>,
6868
MessengerEvents<NetworkControllerMessenger>
6969
>({ namespace: MOCK_ANY_NAMESPACE });
70-
rootMessenger.registerActionHandler(
71-
'ErrorReportingService:captureException',
72-
jest.fn(),
73-
);
70+
7471
return rootMessenger;
7572
};
7673

@@ -93,10 +90,7 @@ const setupNetworkController = async ({
9390
>({
9491
namespace: 'NetworkController',
9592
parent: rootMessenger,
96-
});
97-
rootMessenger.delegate({
98-
messenger: networkControllerMessenger,
99-
actions: ['ErrorReportingService:captureException'],
93+
captureException: jest.fn(),
10094
});
10195

10296
const infuraProjectId = '123';

packages/multichain-account-service/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Bump `@metamask/snaps-sdk` from `^9.0.0` to `^10.3.0` ([#7550](https://github.com/MetaMask/core/pull/7550))
1414
- Bump `@metamask/snaps-utils` from `^11.0.0` to `^11.7.0` ([#7550](https://github.com/MetaMask/core/pull/7550))
1515
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
16+
- Remove dependency on `@metamask/error-reporting-service` ([#7542](https://github.com/MetaMask/core/pull/7542))
17+
- The service no longer needs `ErrorReportingService:captureException`.
1618

1719
## [4.1.0]
1820

packages/multichain-account-service/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@ethereumjs/util": "^9.1.0",
5252
"@metamask/accounts-controller": "^35.0.0",
5353
"@metamask/base-controller": "^9.0.0",
54-
"@metamask/error-reporting-service": "^3.0.1",
5554
"@metamask/eth-snap-keyring": "^18.0.0",
5655
"@metamask/key-tree": "^10.1.1",
5756
"@metamask/keyring-api": "^21.0.0",

packages/multichain-account-service/src/MultichainAccountGroup.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ function setup({
5050
});
5151

5252
const serviceMessenger = getMultichainAccountServiceMessenger(messenger);
53-
messenger.registerActionHandler(
54-
'ErrorReportingService:captureException',
55-
jest.fn(),
56-
);
5753

5854
const wallet = new MultichainAccountWallet<Bip44Account<InternalAccount>>({
5955
entropySource: MOCK_WALLET_1_ENTROPY_SOURCE,
@@ -228,13 +224,15 @@ describe('MultichainAccount', () => {
228224
});
229225
const providerError = new Error('Unable to create accounts');
230226
providers[1].createAccounts.mockRejectedValueOnce(providerError);
231-
const callSpy = jest.spyOn(messenger, 'call');
227+
const captureExceptionSpy = jest.spyOn(messenger, 'captureException');
232228
await group.alignAccounts();
233-
expect(callSpy).toHaveBeenCalledWith(
234-
'ErrorReportingService:captureException',
229+
expect(captureExceptionSpy).toHaveBeenCalledWith(
235230
new Error('Unable to align accounts with provider "Mocked Provider"'),
236231
);
237-
expect(callSpy.mock.lastCall[1]).toHaveProperty('cause', providerError);
232+
expect(captureExceptionSpy.mock.lastCall[0]).toHaveProperty(
233+
'cause',
234+
providerError,
235+
);
238236
});
239237
});
240238
});

packages/multichain-account-service/src/MultichainAccountGroup.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,7 @@ export class MultichainAccountGroup<
265265
provider: provider.getName(),
266266
},
267267
);
268-
this.#messenger.call(
269-
'ErrorReportingService:captureException',
270-
sentryError,
271-
);
268+
this.#messenger.captureException?.(sentryError);
272269
throw error;
273270
}
274271
}),

packages/multichain-account-service/src/MultichainAccountService.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,8 @@ describe('MultichainAccountService', () => {
10411041

10421042
it('does not throw if any providers is throwing', async () => {
10431043
const rootMessenger = getRootMessenger();
1044+
const captureExceptionSpy = jest.spyOn(rootMessenger, 'captureException');
1045+
10441046
const { service, mocks } = await setup({
10451047
rootMessenger,
10461048
accounts: [MOCK_HD_ACCOUNT_1],
@@ -1049,19 +1051,13 @@ describe('MultichainAccountService', () => {
10491051
const providerError = new Error('Unable to resync accounts');
10501052
mocks.SolAccountProvider.resyncAccounts.mockRejectedValue(providerError);
10511053

1052-
const mockCaptureException = jest.fn();
1053-
rootMessenger.registerActionHandler(
1054-
'ErrorReportingService:captureException',
1055-
mockCaptureException,
1056-
);
1057-
10581054
await service.resyncAccounts(); // Should not throw.
10591055

10601056
expect(mocks.EvmAccountProvider.resyncAccounts).toHaveBeenCalled();
10611057
expect(mocks.SolAccountProvider.resyncAccounts).toHaveBeenCalled();
10621058

1063-
expect(mockCaptureException).toHaveBeenCalled();
1064-
expect(mockCaptureException.mock.lastCall[0]).toHaveProperty(
1059+
expect(captureExceptionSpy).toHaveBeenCalled();
1060+
expect(captureExceptionSpy.mock.lastCall[0]).toHaveProperty(
10651061
'cause',
10661062
providerError,
10671063
);

packages/multichain-account-service/src/MultichainAccountService.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ export class MultichainAccountService {
254254
const sentryError = createSentryError(errorMessage, error as Error, {
255255
provider: provider.getName(),
256256
});
257-
this.#messenger.call(
258-
'ErrorReportingService:captureException',
259-
sentryError,
260-
);
257+
this.#messenger.captureException?.(sentryError);
261258
}
262259
}),
263260
);

packages/multichain-account-service/src/MultichainAccountWallet.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ function setup({
6262

6363
const serviceMessenger = getMultichainAccountServiceMessenger(messenger);
6464

65-
messenger.registerActionHandler(
66-
'ErrorReportingService:captureException',
67-
jest.fn(),
68-
);
69-
7065
const wallet = new MultichainAccountWallet<Bip44Account<InternalAccount>>({
7166
entropySource,
7267
providers,
@@ -373,17 +368,19 @@ describe('MultichainAccountWallet', () => {
373368
const [provider] = providers;
374369
const providerError = new Error('Unable to create accounts');
375370
provider.createAccounts.mockRejectedValueOnce(providerError);
376-
const callSpy = jest.spyOn(messenger, 'call');
371+
const captureExceptionSpy = jest.spyOn(messenger, 'captureException');
377372
await expect(
378373
wallet.createMultichainAccountGroup(groupIndex),
379374
).rejects.toThrow(
380375
'Unable to create multichain account group for index: 1',
381376
);
382-
expect(callSpy).toHaveBeenCalledWith(
383-
'ErrorReportingService:captureException',
377+
expect(captureExceptionSpy).toHaveBeenCalledWith(
384378
new Error('Unable to create account with provider "Mocked Provider 0"'),
385379
);
386-
expect(callSpy.mock.lastCall[1]).toHaveProperty('cause', providerError);
380+
expect(captureExceptionSpy.mock.lastCall[0]).toHaveProperty(
381+
'cause',
382+
providerError,
383+
);
387384
});
388385

389386
it('aggregates non-EVM failures when waiting for all providers', async () => {
@@ -732,15 +729,17 @@ describe('MultichainAccountWallet', () => {
732729
});
733730
const providerError = new Error('Unable to discover accounts');
734731
providers[0].discoverAccounts.mockRejectedValueOnce(providerError);
735-
const callSpy = jest.spyOn(messenger, 'call');
732+
const captureExceptionSpy = jest.spyOn(messenger, 'captureException');
736733
// Ensure the other provider stops immediately to finish the Promise.all
737734
providers[1].discoverAccounts.mockResolvedValueOnce([]);
738735
await wallet.discoverAccounts();
739-
expect(callSpy).toHaveBeenCalledWith(
740-
'ErrorReportingService:captureException',
736+
expect(captureExceptionSpy).toHaveBeenCalledWith(
741737
new Error('Unable to discover accounts'),
742738
);
743-
expect(callSpy.mock.lastCall[1]).toHaveProperty('cause', providerError);
739+
expect(captureExceptionSpy.mock.lastCall[0]).toHaveProperty(
740+
'cause',
741+
providerError,
742+
);
744743
});
745744
});
746745
});

packages/multichain-account-service/src/MultichainAccountWallet.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ export class MultichainAccountWallet<
259259
provider: provider.getName(),
260260
},
261261
);
262-
this.#messenger.call(
263-
'ErrorReportingService:captureException',
264-
sentryError,
265-
);
262+
this.#messenger.captureException?.(sentryError);
266263
throw error;
267264
}),
268265
);
@@ -301,10 +298,7 @@ export class MultichainAccountWallet<
301298
provider: provider.getName(),
302299
},
303300
);
304-
this.#messenger.call(
305-
'ErrorReportingService:captureException',
306-
sentryError,
307-
);
301+
this.#messenger.captureException?.(sentryError);
308302
});
309303
});
310304
}
@@ -448,10 +442,7 @@ export class MultichainAccountWallet<
448442
provider: evmProvider.getName(),
449443
},
450444
);
451-
this.#messenger.call(
452-
'ErrorReportingService:captureException',
453-
sentryError,
454-
);
445+
this.#messenger.captureException?.(sentryError);
455446
throw new Error(errorMessage);
456447
}
457448

@@ -624,10 +615,7 @@ export class MultichainAccountWallet<
624615
groupIndex: targetGroupIndex,
625616
},
626617
);
627-
this.#messenger.call(
628-
'ErrorReportingService:captureException',
629-
sentryError,
630-
);
618+
this.#messenger.captureException?.(sentryError);
631619
break;
632620
}
633621

0 commit comments

Comments
 (0)