openvibers/openvibe.live Commits

Pastes: fix the null-metadata crash that broke every new paste

OP OpenVibers committed 19 Aug 2026 · c3617baaf4 · 2 files, +8 −3

Root cause, now that the render error is no longer masked:

    can't access property "ai_moment", meta is null

    let meta;
    try { meta = JSON.parse(p.metadata); } catch { meta = {}; }
    ...
    meta.ai_moment                                    // TypeError

JSON.parse(null) RETURNS null rather than throwing, so the catch never fired and
meta was null for every paste without metadata — which is every newly created
one. The next line dereferenced it, the render died, and the outer catch
reported "Paste not found". Pastes that happened to carry metadata (AI moments,
screenshots) rendered fine, which is why this looked like it only affected new
pastes.

Guard the value, not just the parse: skip the parse when there is nothing to
parse, and coerce any non-object result to {}.

Swept the rest of the codebase for the same shape; the other JSON.parse calls
either read a non-null source and return on failure, or are already guarded.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xw6Sf5zzSALw8m93XNu5JE

Changes

ddiff --git a/public/index.html b/public/index.html
iindex 7dbe6f2f..cb503979 100644
---- a/public/index.html
++++ b/public/index.html
@@@ -5041,7 +5041,7 @@ curl -s https://openvibe.media/live/@Goosely/chat-insight.json | jq ".chat_insig
<script src="/js/dashboard-moderation.js?v=5" defer></script>
<script src="/js/ai-viewers.js?v=1" defer></script>
<script src="/js/powerchat.js?v=6" defer></script>
--<script src="/js/pastes.js?v=12" defer></script>
++<script src="/js/pastes.js?v=13" defer></script>
<script src="/js/draggable-fab.js?v=2" defer></script>
<script src="/js/messenger.js?v=2" defer></script>
ddiff --git a/public/js/pastes.js b/public/js/pastes.js
iindex d21213d8..59d750a1 100644
---- a/public/js/pastes.js
++++ b/public/js/pastes.js
@@@ -265,8 +265,13 @@ async function loadPasteViewer(slug) {
const userLiked = !!p.liked;
const paste_id_for_js = p.id;
-- let meta;
-- try { meta = JSON.parse(p.metadata); } catch { meta = {}; }
++ // JSON.parse(null) returns null instead of throwing, so the catch never fired and
++ // `meta` came back null for every paste with no metadata — i.e. every newly created
++ // one. The next line then read meta.ai_moment and the whole render died, which the
++ // outer catch reported as "Paste not found". Guard the value, not just the parse.
++ let meta = {};
++ try { if (p.metadata) meta = JSON.parse(p.metadata); } catch { meta = {}; }
++ if (!meta || typeof meta !== 'object') meta = {};
// AI "crazy moment" pastes carry a link back to the exact VOD timestamp they were
// grabbed from — surface it as a real button (and drop the raw "▶ Watch…" line the