diff options
| author | adamelmore <[email protected]> | 2026-01-27 06:27:27 -0600 |
|---|---|---|
| committer | adamelmore <[email protected]> | 2026-01-27 06:29:20 -0600 |
| commit | 095328faf439fbdc62506f3653875fbfec5c60ab (patch) | |
| tree | 707036011dcafaa2ad13d05eb52b041ea6f0d951 /packages/app/src/utils | |
| parent | 743e83d9bfc050183be5bfb0f241ebe5faac6b35 (diff) | |
| download | opencode-095328faf439fbdc62506f3653875fbfec5c60ab.tar.gz opencode-095328faf439fbdc62506f3653875fbfec5c60ab.zip | |
fix(app): non-fatal error handling
Diffstat (limited to 'packages/app/src/utils')
| -rw-r--r-- | packages/app/src/utils/base64.ts | 10 | ||||
| -rw-r--r-- | packages/app/src/utils/persist.ts | 30 |
2 files changed, 36 insertions, 4 deletions
diff --git a/packages/app/src/utils/base64.ts b/packages/app/src/utils/base64.ts new file mode 100644 index 000000000..c1f9d88c6 --- /dev/null +++ b/packages/app/src/utils/base64.ts @@ -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 + } +} diff --git a/packages/app/src/utils/persist.ts b/packages/app/src/utils/persist.ts index 70884977c..129695f86 100644 --- a/packages/app/src/utils/persist.ts +++ b/packages/app/src/utils/persist.ts @@ -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 + } }, } } |
