Skip to content

Commit b4c1f9c

Browse files
legobeatGudahtt
authored andcommitted
fix(deps): update from eth-rpc-errors to @metamask/rpc-errors (cause edition) (#24496)
- Upgrade from obsolete `eth-rpc-errors` to `@metamask/rpc-errors` - This introduce handling of error causes See [here](MetaMask/rpc-errors#140) for some context. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24496?quickstart=1) - #22871 - [x] MetaMask/rpc-errors#158 - [x] MetaMask/rpc-errors#144 - [x] MetaMask/rpc-errors#140 - #22875 - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 22bf4ad commit b4c1f9c

File tree

49 files changed

+1378
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1378
-290
lines changed

app/scripts/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isObject } from '@metamask/utils';
1818
import { ApprovalType } from '@metamask/controller-utils';
1919
import PortStream from 'extension-port-stream';
2020

21-
import { ethErrors } from 'eth-rpc-errors';
21+
import { providerErrors } from '@metamask/rpc-errors';
2222
import { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';
2323
import { NotificationServicesController } from '@metamask/notification-services-controller';
2424

@@ -1156,7 +1156,7 @@ export function setupController(
11561156
default:
11571157
controller.approvalController.reject(
11581158
id,
1159-
ethErrors.provider.userRejectedRequest(),
1159+
providerErrors.userRejectedRequest(),
11601160
);
11611161
break;
11621162
}

app/scripts/lib/createMetaRPCHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethErrors, serializeError } from 'eth-rpc-errors';
1+
import { rpcErrors, serializeError } from '@metamask/rpc-errors';
22
import { isStreamWritable } from './stream-utils';
33

44
const createMetaRPCHandler = (api, outStream) => {
@@ -9,7 +9,7 @@ const createMetaRPCHandler = (api, outStream) => {
99
if (!api[data.method]) {
1010
outStream.write({
1111
jsonrpc: '2.0',
12-
error: ethErrors.rpc.methodNotFound({
12+
error: rpcErrors.methodNotFound({
1313
message: `${data.method} not found`,
1414
}),
1515
id: data.id,

app/scripts/lib/createMetaRPCHandler.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe('createMetaRPCHandler', () => {
7171
});
7272
streamTest.on('data', (data) => {
7373
expect(data.error.message).toStrictEqual('foo-error');
74+
expect(data.error.data.cause.message).toStrictEqual('foo-error');
7475
streamTest.end();
7576
});
7677
});

app/scripts/lib/createRPCMethodTrackingMiddleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApprovalType, detectSIWE } from '@metamask/controller-utils';
2-
import { errorCodes } from 'eth-rpc-errors';
2+
import { errorCodes } from '@metamask/rpc-errors';
33
import { isValidAddress } from 'ethereumjs-util';
44
import { MESSAGE_TYPE, ORIGIN_METAMASK } from '../../../shared/constants/app';
55
import {

app/scripts/lib/createRPCMethodTrackingMiddleware.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { errorCodes } from 'eth-rpc-errors';
1+
import { errorCodes } from '@metamask/rpc-errors';
22
import { detectSIWE } from '@metamask/controller-utils';
33

44
import MetaMetricsController from '../controllers/metametrics';

app/scripts/lib/metaRPCClientFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EthereumRpcError } from 'eth-rpc-errors';
1+
import { JsonRpcError } from '@metamask/rpc-errors';
22
import SafeEventEmitter from '@metamask/safe-event-emitter';
33
import createRandomId from '../../../shared/modules/random-id';
44
import { TEN_SECONDS_IN_MILLISECONDS } from '../../../shared/lib/transactions-controller-utils';
@@ -77,7 +77,7 @@ class MetaRPCClient {
7777
}
7878

7979
if (error) {
80-
const e = new EthereumRpcError(error.code, error.message, error.data);
80+
const e = new JsonRpcError(error.code, error.message, error.data);
8181
// preserve the stack from serializeError
8282
e.stack = error.stack;
8383
if (cb) {

app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { permissionRpcMethods } from '@metamask/permission-controller';
2+
import { rpcErrors } from '@metamask/rpc-errors';
23
import { selectHooks } from '@metamask/snaps-rpc-methods';
34
import { hasProperty } from '@metamask/utils';
4-
import { ethErrors } from 'eth-rpc-errors';
55
import { handlers as localHandlers, legacyHandlers } from './handlers';
66

77
const allHandlers = [...localHandlers, ...permissionRpcMethods.handlers];
@@ -67,7 +67,7 @@ function makeMethodMiddlewareMaker(handlers) {
6767
return end(
6868
error instanceof Error
6969
? error
70-
: ethErrors.rpc.internal({ data: error }),
70+
: rpcErrors.internal({ data: error }),
7171
);
7272
}
7373
}

app/scripts/lib/rpc-method-middleware/createUnsupportedMethodMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethErrors } from 'eth-rpc-errors';
1+
import { rpcErrors } from '@metamask/rpc-errors';
22
import type { JsonRpcMiddleware } from 'json-rpc-engine';
33
import { UNSUPPORTED_RPC_METHODS } from '../../../../shared/constants/network';
44

@@ -12,7 +12,7 @@ export function createUnsupportedMethodMiddleware(): JsonRpcMiddleware<
1212
> {
1313
return async function unsupportedMethodMiddleware(req, _res, next, end) {
1414
if ((UNSUPPORTED_RPC_METHODS as Set<string>).has(req.method)) {
15-
return end(ethErrors.rpc.methodNotSupported());
15+
return end(rpcErrors.methodNotSupported());
1616
}
1717
return next();
1818
};

app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ApprovalType } from '@metamask/controller-utils';
21
import * as URI from 'uri-js';
2+
import { ApprovalType } from '@metamask/controller-utils';
33
import { RpcEndpointType } from '@metamask/network-controller';
4-
import { ethErrors } from 'eth-rpc-errors';
4+
import { rpcErrors } from '@metamask/rpc-errors';
55
import { cloneDeep } from 'lodash';
66
import { MESSAGE_TYPE } from '../../../../../shared/constants/app';
77
import {
@@ -76,7 +76,7 @@ async function addEthereumChainHandler(
7676
existingNetwork.nativeCurrency !== ticker
7777
) {
7878
return end(
79-
ethErrors.rpc.invalidParams({
79+
rpcErrors.invalidParams({
8080
message: `nativeCurrency.symbol does not match currency symbol for a network the user already has added with the same chainId. Received:\n${ticker}`,
8181
}),
8282
);

app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethErrors } from 'eth-rpc-errors';
1+
import { rpcErrors } from '@metamask/rpc-errors';
22
import { CHAIN_IDS } from '../../../../../shared/constants/network';
33
import addEthereumChain from './add-ethereum-chain';
44

@@ -365,7 +365,7 @@ describe('addEthereumChainHandler', () => {
365365
);
366366

367367
expect(mockEnd).toHaveBeenCalledWith(
368-
ethErrors.rpc.invalidParams({
368+
rpcErrors.invalidParams({
369369
message: `Expected 0x-prefixed, unpadded, non-zero hexadecimal string 'chainId'. Received:\ninvalid_chain_id`,
370370
}),
371371
);
@@ -592,7 +592,7 @@ describe('addEthereumChainHandler', () => {
592592
);
593593

594594
expect(mockEnd).toHaveBeenCalledWith(
595-
ethErrors.rpc.invalidParams({
595+
rpcErrors.invalidParams({
596596
message: `Received unexpected keys on object parameter. Unsupported keys:\n${unexpectedParam}`,
597597
}),
598598
);
@@ -676,7 +676,7 @@ describe('addEthereumChainHandler', () => {
676676
);
677677

678678
expect(mockEnd).toHaveBeenCalledWith(
679-
ethErrors.rpc.invalidParams({
679+
rpcErrors.invalidParams({
680680
message: `nativeCurrency.symbol does not match currency symbol for a network the user already has added with the same chainId. Received:\nWRONG`,
681681
}),
682682
);

0 commit comments

Comments
 (0)