diff --git a/src/state/persisted/store.ts b/src/state/persisted/store.ts index bb7fbed890..93f05651c3 100644 --- a/src/state/persisted/store.ts +++ b/src/state/persisted/store.ts @@ -1,7 +1,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage' -import {Schema, schema} from '#/state/persisted/schema' import {logger} from '#/logger' +import {Schema, schema} from '#/state/persisted/schema' const BSKY_STORAGE = 'BSKY_STORAGE' @@ -13,8 +13,17 @@ export async function write(value: Schema) { export async function read(): Promise { const rawData = await AsyncStorage.getItem(BSKY_STORAGE) const objData = rawData ? JSON.parse(rawData) : undefined - if (schema.safeParse(objData).success) { + const parsed = schema.safeParse(objData) + if (parsed.success) { return objData + } else { + const errors = parsed.error.errors.map(e => ({ + code: e.code, + expected: e.expected, + path: e.path, + })) + logger.error(`persisted store: data failed validation on read`, {errors}) + return undefined } }