-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve Keyring/Accounts error handling and logs (#12822)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR does the following 1. unmasks non sensitive data from the Accounts Controller and Keyring controller to help us better debug issues in prod. This means that more data will be provided in the sentry state logs. I have ensured that all addresses have remained masked 2. adds logs when creating key components such as the engine and the accounts controller. This will help us debug issues with empty state. 3. adds validation to the migrations for key components. Currently we are validating that the accounts controller and keyring controller data are sound. This validation will not block the app from initializing but will log the errors it finds. ## **Related issues** Progresses : #12408 ## **Manual testing steps** 1. this change only adds logs and error handling to the app so there should be no functional changes. that being said, we should still verify that the upgrade path is working. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] 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.
- Loading branch information
1 parent
5a38279
commit b1e29d0
Showing
22 changed files
with
1,182 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/core/Engine/controllers/AccountsController/logger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Logger from '../../../../util/Logger'; | ||
import { logAccountsControllerCreation } from './logger'; | ||
import { defaultAccountsControllerState } from './utils'; | ||
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../../util/test/accountsControllerTestUtils'; | ||
|
||
jest.mock('../../../../util/Logger'); | ||
|
||
describe('logAccountsControllerCreation', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('logs creation with default state when no initial state provided', () => { | ||
logAccountsControllerCreation(); | ||
|
||
expect(Logger.log).toHaveBeenCalledWith( | ||
'Creating AccountsController with default state', | ||
{ | ||
defaultState: defaultAccountsControllerState, | ||
}, | ||
); | ||
}); | ||
|
||
it('logs creation with empty initial state', () => { | ||
const initialState = { | ||
internalAccounts: { | ||
accounts: {}, | ||
selectedAccount: '', | ||
}, | ||
}; | ||
|
||
logAccountsControllerCreation(initialState); | ||
|
||
expect(Logger.log).toHaveBeenCalledWith( | ||
'Creating AccountsController with provided initial state', | ||
{ | ||
hasSelectedAccount: false, | ||
accountsCount: 0, | ||
}, | ||
); | ||
}); | ||
|
||
it('logs creation with populated initial state', () => { | ||
logAccountsControllerCreation(MOCK_ACCOUNTS_CONTROLLER_STATE); | ||
|
||
expect(Logger.log).toHaveBeenCalledWith( | ||
'Creating AccountsController with provided initial state', | ||
{ | ||
hasSelectedAccount: true, | ||
accountsCount: 2, | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AccountsControllerState } from '@metamask/accounts-controller'; | ||
import Logger from '../../../../util/Logger'; | ||
import { defaultAccountsControllerState } from './utils'; | ||
|
||
export function logAccountsControllerCreation( | ||
initialState?: AccountsControllerState, | ||
) { | ||
if (!initialState) { | ||
Logger.log('Creating AccountsController with default state', { | ||
defaultState: defaultAccountsControllerState, | ||
}); | ||
} else { | ||
Logger.log('Creating AccountsController with provided initial state', { | ||
hasSelectedAccount: !!initialState.internalAccounts?.selectedAccount, | ||
accountsCount: Object.keys(initialState.internalAccounts?.accounts || {}) | ||
.length, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { KeyringControllerState } from '@metamask/keyring-controller'; | ||
import { EngineState } from '../types'; | ||
import Logger from '../../../util/Logger'; | ||
|
||
export function logEngineCreation( | ||
initialState: Partial<EngineState> = {}, | ||
initialKeyringState?: KeyringControllerState | null, | ||
) { | ||
if (Object.keys(initialState).length === 0) { | ||
Logger.log('Engine initialized with empty state', { | ||
keyringStateFromBackup: !!initialKeyringState, | ||
}); | ||
} else { | ||
Logger.log('Engine initialized with non-empty state', { | ||
hasAccountsState: !!initialState.AccountsController, | ||
hasKeyringState: !!initialState.KeyringController, | ||
keyringStateFromBackup: !!initialKeyringState, | ||
}); | ||
} | ||
} |
Oops, something went wrong.