From 1585c711e015801766ae1f52f6cbdf517c9dd7be Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 16 Aug 2024 15:56:03 -0230 Subject: [PATCH 1/2] fix: Fix migration 120.3 error caused by invalid state For a small number of users, migration 120.3 is failing due to invalid `TransactionController.transactions` state. We aren't sure yet how this is happening, but we can resolve the problem by updating the migration to delete this invalid state if we detect it. No other state relies on this state, and if it's invalid it won't work properly anyway. The migration has been renamed from 120.3 to 120.6 so that it will be re-run for any users who encountered this migration on v12.0.1 already. Fixes #26423 --- .../migrations/{120.3.test.ts => 120.6.test.ts} | 16 ++++++++-------- app/scripts/migrations/{120.3.ts => 120.6.ts} | 9 ++++++--- app/scripts/migrations/index.js | 3 ++- 3 files changed, 16 insertions(+), 12 deletions(-) rename app/scripts/migrations/{120.3.test.ts => 120.6.test.ts} (93%) rename app/scripts/migrations/{120.3.ts => 120.6.ts} (93%) diff --git a/app/scripts/migrations/120.3.test.ts b/app/scripts/migrations/120.6.test.ts similarity index 93% rename from app/scripts/migrations/120.3.test.ts rename to app/scripts/migrations/120.6.test.ts index 11bef64a3422..208122cf8a06 100644 --- a/app/scripts/migrations/120.3.test.ts +++ b/app/scripts/migrations/120.6.test.ts @@ -1,5 +1,5 @@ import { cloneDeep } from 'lodash'; -import { migrate, version } from './120.3'; +import { migrate, version } from './120.6'; const sentryCaptureExceptionMock = jest.fn(); @@ -7,9 +7,9 @@ global.sentry = { captureException: sentryCaptureExceptionMock, }; -const oldVersion = 120.2; +const oldVersion = 120.5; -describe('migration #120.3', () => { +describe('migration #120.6', () => { afterEach(() => { jest.resetAllMocks(); }); @@ -72,7 +72,7 @@ describe('migration #120.3', () => { expect(newStorage.data).toStrictEqual(oldStorageDataClone); }); - it('reports error and returns state unchanged if transactions property is invalid', async () => { + it('removes transactions property if it is invalid', async () => { const oldStorage = { meta: { version: oldVersion }, data: { @@ -86,10 +86,10 @@ describe('migration #120.3', () => { const newStorage = await migrate(oldStorage); - expect(sentryCaptureExceptionMock).toHaveBeenCalledWith( - `Migration ${version}: Invalid TransactionController transactions state of type 'string'`, - ); - expect(newStorage.data).toStrictEqual(oldStorageDataClone); + expect(newStorage.data).toStrictEqual({ + PreferencesController: {}, + TransactionController: {}, + }); }); it('reports error and returns state unchanged if there is an invalid transaction', async () => { diff --git a/app/scripts/migrations/120.3.ts b/app/scripts/migrations/120.6.ts similarity index 93% rename from app/scripts/migrations/120.3.ts rename to app/scripts/migrations/120.6.ts index 139e6f5221c2..70be368f0c98 100644 --- a/app/scripts/migrations/120.3.ts +++ b/app/scripts/migrations/120.6.ts @@ -7,7 +7,7 @@ type VersionedData = { data: Record; }; -export const version = 120.3; +export const version = 120.6; const MAX_TRANSACTION_HISTORY_LENGTH = 100; @@ -52,9 +52,12 @@ function transformState(state: Record): void { ); return; } else if (!Array.isArray(transactionControllerState.transactions)) { - global.sentry?.captureException( - `Migration ${version}: Invalid TransactionController transactions state of type '${typeof transactionControllerState.transactions}'`, + log.error( + new Error( + `Migration ${version}: Invalid TransactionController transactions state of type '${typeof transactionControllerState.transactions}'`, + ), ); + delete transactionControllerState.transactions; return; } diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index f4757c22fdf8..305343e7124f 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -133,9 +133,10 @@ const migrations = [ require('./120'), require('./120.1'), require('./120.2'), - require('./120.3'), + // require('./120.3'), Renamed to 120.6, do not re-use this number require('./120.4'), require('./120.5'), + require('./120.6'), require('./121'), require('./122'), require('./123'), From b47d2af0bd7c2eac9357d5ed2728e60c8c6d1262 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 16 Aug 2024 16:16:44 -0230 Subject: [PATCH 2/2] Remove unused variable --- app/scripts/migrations/120.6.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/scripts/migrations/120.6.test.ts b/app/scripts/migrations/120.6.test.ts index 208122cf8a06..1a7daa3aa225 100644 --- a/app/scripts/migrations/120.6.test.ts +++ b/app/scripts/migrations/120.6.test.ts @@ -82,7 +82,6 @@ describe('migration #120.6', () => { }, }, }; - const oldStorageDataClone = cloneDeep(oldStorage.data); const newStorage = await migrate(oldStorage);