Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Report persisted schema validation failures (#4358)

* Report persisted schema validation failures

* Make it safer

authored by

Eric Bailey and committed by
GitHub
a2d5343a b5ac4504

+13 -2
+13 -2
src/state/persisted/store.ts
··· 1 1 import AsyncStorage from '@react-native-async-storage/async-storage' 2 2 3 - import {Schema, schema} from '#/state/persisted/schema' 4 3 import {logger} from '#/logger' 4 + import {Schema, schema} from '#/state/persisted/schema' 5 5 6 6 const BSKY_STORAGE = 'BSKY_STORAGE' 7 7 ··· 13 13 export async function read(): Promise<Schema | undefined> { 14 14 const rawData = await AsyncStorage.getItem(BSKY_STORAGE) 15 15 const objData = rawData ? JSON.parse(rawData) : undefined 16 - if (schema.safeParse(objData).success) { 16 + const parsed = schema.safeParse(objData) 17 + if (parsed.success) { 17 18 return objData 19 + } else { 20 + const errors = 21 + parsed.error?.errors?.map(e => ({ 22 + code: e.code, 23 + // @ts-ignore exists on some types 24 + expected: e?.expected, 25 + path: e.path, 26 + })) || [] 27 + logger.error(`persisted store: data failed validation on read`, {errors}) 28 + return undefined 18 29 } 19 30 } 20 31