fix(app): non-fatal error handling
This commit is contained in:
parent
743e83d9bf
commit
095328faf4
14 changed files with 341 additions and 199 deletions
10
packages/app/src/utils/base64.ts
Normal file
10
packages/app/src/utils/base64.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { base64Decode } from "@opencode-ai/util/encode"
|
||||
|
||||
export function decode64(value: string | undefined) {
|
||||
if (value === undefined) return
|
||||
try {
|
||||
return base64Decode(value)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -151,7 +151,14 @@ function localStorageWithPrefix(prefix: string): SyncStorage {
|
|||
const cached = cache.get(name)
|
||||
if (fallback.disabled && cached !== undefined) return cached
|
||||
|
||||
const stored = localStorage.getItem(name)
|
||||
const stored = (() => {
|
||||
try {
|
||||
return localStorage.getItem(name)
|
||||
} catch {
|
||||
fallback.disabled = true
|
||||
return null
|
||||
}
|
||||
})()
|
||||
if (stored === null) return cached ?? null
|
||||
cache.set(name, stored)
|
||||
return stored
|
||||
|
|
@ -172,7 +179,11 @@ function localStorageWithPrefix(prefix: string): SyncStorage {
|
|||
const name = item(key)
|
||||
cache.delete(name)
|
||||
if (fallback.disabled) return
|
||||
localStorage.removeItem(name)
|
||||
try {
|
||||
localStorage.removeItem(name)
|
||||
} catch {
|
||||
fallback.disabled = true
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -183,7 +194,14 @@ function localStorageDirect(): SyncStorage {
|
|||
const cached = cache.get(key)
|
||||
if (fallback.disabled && cached !== undefined) return cached
|
||||
|
||||
const stored = localStorage.getItem(key)
|
||||
const stored = (() => {
|
||||
try {
|
||||
return localStorage.getItem(key)
|
||||
} catch {
|
||||
fallback.disabled = true
|
||||
return null
|
||||
}
|
||||
})()
|
||||
if (stored === null) return cached ?? null
|
||||
cache.set(key, stored)
|
||||
return stored
|
||||
|
|
@ -202,7 +220,11 @@ function localStorageDirect(): SyncStorage {
|
|||
removeItem: (key) => {
|
||||
cache.delete(key)
|
||||
if (fallback.disabled) return
|
||||
localStorage.removeItem(key)
|
||||
try {
|
||||
localStorage.removeItem(key)
|
||||
} catch {
|
||||
fallback.disabled = true
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue