Page MenuHomePhabricator

[native] clear database when malformation is detected
ClosedPublic

Authored by kamil on Dec 22 2022, 2:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 3, 2:30 AM
Unknown Object (File)
Wed, Apr 3, 2:30 AM
Unknown Object (File)
Wed, Apr 3, 2:30 AM
Unknown Object (File)
Wed, Apr 3, 2:30 AM
Unknown Object (File)
Wed, Apr 3, 2:30 AM
Unknown Object (File)
Thu, Mar 28, 4:54 PM
Unknown Object (File)
Mar 6 2024, 9:47 AM
Unknown Object (File)
Mar 3 2024, 9:30 PM
Subscribers

Details

Summary

This code will execute when database initialization will fail for the second time. Should delete database and perform "soft login".
Context in ENG-2071

Test Plan

Make this code execute and check if new database is created, user is re-logged and data in database is populated

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Dec 22 2022, 3:31 AM
native/data/sqlite-data-handler.js
88–102 ↗(On Diff #20018)

A couple of issues here:

  1. This is repeated code that can be extracted into separate function.
  2. Is it intentional not to surround this call to clearSensitiveData with try catch statement? All database queries in this class are checked against thrown exceptions. If we want an exception to be thrown here then will any exception work? Perhaps we should add some filtering to narrow the scope of exceptions ? This component is one of the most volatile in the codebase - we must be very conscious about every decision we make.
  3. Is there a way to merge this functionality with handleSensitiveData? Are we sure we need to to call clearSensitiveData possibly twice? Not saying that calling at most twice is not correct, but if we can also do correct calling at most once, then we should proceed this way.
104–112 ↗(On Diff #20018)

This is also repeated code that could be refactored into function.

native/data/sqlite-data-handler.js
88–102 ↗(On Diff #20018)

This is repeated code that can be extracted into separate function.

Right, done

> Is it intentional not to surround this call to clearSensitiveData with try catch statement?

No, it's my mistake, thanks for pointing

Is there a way to merge this functionality with handleSensitiveData?

I am afraid it'll be hard, handleSensitiveData uses database in its logic, and in this scenario - database is malformed so it'll be hard to achieve something workable and readable simultaneously.

Are we sure we need to to call clearSensitiveData possibly twice?

Are you sure about this? after the malformed database is detected we return from this function, or do you have in mind some sort of race condition?

marcin added a reviewer: tomek.
tomek requested changes to this revision.Jan 11 2023, 3:28 AM
tomek added inline comments.
lib/types/account-types.js
90 ↗(On Diff #20688)

For me a word corrupted better describes the state, but up to you.

native/data/sqlite-data-handler.js
123–127 ↗(On Diff #20688)

Why do we have a different approach here? Shouldn't we just throw in both cases?

This revision now requires changes to proceed.Jan 11 2023, 3:28 AM

rename source

lib/types/account-types.js
90 ↗(On Diff #20688)

Agree with you, updating

native/data/sqlite-data-handler.js
123–127 ↗(On Diff #20688)

I wanted to make it work the same way as clearing sensitive data after logout (see lines 99-109). Do you think we should update this? Or modify only this case?

tomek added inline comments.
native/data/sqlite-data-handler.js
121 ↗(On Diff #21584)
134 ↗(On Diff #21584)

Do we need this return?

123–127 ↗(On Diff #20688)

I'm not sure why I've asked about it, but this code makes sense and let's keep it.

This revision is now accepted and ready to land.Jan 31 2023, 5:30 AM
native/data/sqlite-data-handler.js
134 ↗(On Diff #21584)

It is useful - let's keep it.

Do you think we can get rid of these alerts now? Having to click through the alerts is kind of getting annoying on iOS Simulator.

Yeah we can probably get rid of them, feel free to put up a diff

native/data/sqlite-data-handler.js
187

We're no longer using several of these directly in the dep list, so they can be removed. I'm actually not sure why the React hook ESLint rules didn't catch this

native/data/sqlite-data-handler.js
193

It's not clear why this one was added to the dep list... it doesn't appear to be used in the effect