Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/livecodes/storage/simple-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ export const createSimpleStorage = <T>(name: StoreName, isEmbed: boolean): Simpl
};

const setValue = (value: T | null) => {
window.localStorage.setItem(name, JSON.stringify(value));
notifyPub();
try {
window.localStorage.setItem(name, JSON.stringify(value));
notifyPub();
} catch {
// exceeded quota
}
Comment on lines +25 to +30
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Silent catch swallows all errors, risking unnoticed data loss.

Two concerns:

  1. No user/developer feedback — if a write silently fails, the user may lose data (e.g. settings, unsaved state) with no indication. Consider at least a console.warn so it's debuggable, and ideally surfacing a notification to the user.

  2. Overly broad catch — this catches every exception (e.g., SecurityError when storage is disabled, TypeError from JSON.stringify on circular refs), not just QuotaExceededError. Non-quota errors likely indicate bugs worth surfacing.

Proposed fix: narrow the catch and add minimal logging
   const setValue = (value: T | null) => {
     try {
       window.localStorage.setItem(name, JSON.stringify(value));
       notifyPub();
     } catch {
-      // exceeded quota
+    } catch (e) {
+      if (e instanceof DOMException && e.name === 'QuotaExceededError') {
+        console.warn(`[simple-storage] localStorage quota exceeded for "${name}"`);
+      } else {
+        throw e;
+      }
     }
   };
🤖 Prompt for AI Agents
In `@src/livecodes/storage/simple-storage.ts` around lines 25 - 30, The try/catch
around window.localStorage.setItem(name, JSON.stringify(value)) in
simple-storage.ts currently swallows all errors; narrow it to only handle
storage-quota/security cases and surface others: catch
DOMException/QuotaExceededError (or check err.name/err.code) and in that branch
call notifyPub() as appropriate and emit a console.warn (or trigger a user
notification) with the error and the key name, but rethrow or propagate
non-quota errors (e.g., JSON.stringify TypeError) so bugs are not hidden;
reference the setItem call, the surrounding try/catch, and notifyPub to locate
where to implement this change.

};

const getValue = (): T | null => {
Expand Down