about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-06-04 14:51:28 -0500
committerGitHub <noreply@github.com>2024-06-04 20:51:28 +0100
commita2d5343a87c05ac5640abba5c50712e2a10a7958 (patch)
tree838e55247284552838809d0c5fe9e6dab638afbc /src
parentb5ac45044295988f11751c191eb91e36fb141478 (diff)
downloadvoidsky-a2d5343a87c05ac5640abba5c50712e2a10a7958.tar.zst
Report persisted schema validation failures (#4358)
* Report persisted schema validation failures

* Make it safer
Diffstat (limited to 'src')
-rw-r--r--src/state/persisted/store.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/state/persisted/store.ts b/src/state/persisted/store.ts
index bb7fbed89..421bdccdf 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,19 @@ export async function write(value: Schema) {
 export async function read(): Promise<Schema | undefined> {
   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,
+        // @ts-ignore exists on some types
+        expected: e?.expected,
+        path: e.path,
+      })) || []
+    logger.error(`persisted store: data failed validation on read`, {errors})
+    return undefined
   }
 }