Remove fallback, not needed, update logs

This commit is contained in:
Eric Bailey
2023-12-05 16:53:14 -06:00
parent 60e265ab04
commit 94ec8e0ace
2 changed files with 6 additions and 22 deletions
+4 -1
View File
@@ -26,7 +26,10 @@ export async function init() {
try {
await migrate() // migrate old store
const stored = await store.read() // check for new store
if (!stored) await store.write(defaults) // opt: init new store
if (!stored) {
logger.info('persisted state: initializing default storage')
await store.write(defaults) // opt: init new store
}
_state = stored || defaults // return new store
logger.log('persisted state: initialized')
} catch (e) {
+2 -21
View File
@@ -115,7 +115,7 @@ export function transform(legacy: Partial<LegacySchema>): Schema {
* local storage AND old storage exists.
*/
export async function migrate() {
logger.info('persisted state: migrate')
logger.info('persisted state: check need to migrate')
try {
const rawLegacyData = await AsyncStorage.getItem(
@@ -137,6 +137,7 @@ export async function migrate() {
),
})
logger.info(`persisted state: debug new data`, {
hasNewData: Boolean(newData),
hasExistingLoggedInAccount: Boolean(newData?.session?.currentAccount),
numberOfExistingAccounts: newData?.session?.accounts?.length,
existingAccountMatchesLegacy: Boolean(
@@ -144,8 +145,6 @@ export async function migrate() {
legacy?.session?.data?.did,
),
})
} else {
logger.info(`persisted state: no legacy to debug, fresh install`)
}
} catch (e: any) {
logger.error(e, {message: `persisted state: legacy debugging failed`})
@@ -165,24 +164,6 @@ export async function migrate() {
logger.error('persisted state: legacy data failed validation', {
error: validate.error,
})
/*
* If transformed data fails validation, start from a clean slate with
* the new data structure.
*
* If this fails, there's likely something related to AsyncStorage
* going wrong.
*/
try {
await write(transform({}))
logger.log(
'persisted state: recovered from legacy validation failure',
)
} catch (e: any) {
logger.error(e, {
message: 'persisted state: error recovering from legacy migration',
})
}
}
} else {
logger.log('persisted state: no migration needed')