Skip to content

Commit 95ab626

Browse files
committed
fix: fix PR comment
1 parent 3249521 commit 95ab626

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

app/store/migrations/090.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,30 @@ describe('Migration #90 - Replace BSC Network RPC URL', () => {
266266
.networkConfigurationsByChainId[BSC_CHAIN_ID].rpcEndpoints[0].url,
267267
).toBe(NEW_RPC_URL);
268268
});
269+
270+
it('should capture exception when NetworkController structure is invalid', async () => {
271+
const oldState = merge(
272+
{},
273+
{
274+
engine: {
275+
backgroundState: {
276+
NetworkController: {
277+
// Valid object but missing networkConfigurationsByChainId
278+
selectedNetworkClientId: 'mainnet',
279+
networksMetadata: {},
280+
// networkConfigurationsByChainId is intentionally missing
281+
},
282+
},
283+
},
284+
},
285+
);
286+
287+
const newState = await migrate(oldState);
288+
289+
expect(newState).toStrictEqual(oldState);
290+
expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error));
291+
expect(mockedCaptureException.mock.calls[0][0].message).toBe(
292+
'Migration 90: NetworkController or networkConfigurationsByChainId not found in expected state structure. Skipping BSC RPC endpoint migration.',
293+
);
294+
});
269295
});

app/store/migrations/090.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { hasProperty, isObject } from '@metamask/utils';
22
import { ensureValidState } from './util';
33
import Logger from '../../util/Logger';
4+
import { captureException } from '@sentry/react-native';
45
import { RpcEndpointType } from '@metamask/network-controller';
56
import {
67
allowedInfuraHosts,
@@ -123,6 +124,12 @@ export default function migrate(state: unknown) {
123124
}
124125
}
125126
}
127+
} else {
128+
captureException(
129+
new Error(
130+
'Migration 90: NetworkController or networkConfigurationsByChainId not found in expected state structure. Skipping BSC RPC endpoint migration.',
131+
),
132+
);
126133
}
127134

128135
return state;

0 commit comments

Comments
 (0)