openvibers/openvibe.media Commits

Pastes: log why a slug 404s (tenant vs missing)

OP OpenVibers committed 19 Aug 2026 · a6353dc856 · 1 file, +16 −2

'Paste not found' was being reported for pastes that exist, and the 404 was
emitted silently — no way to distinguish a wrong slug, a tenant-scope mismatch
(getPasteBySlug filters on app_id) or a genuinely absent row.

Log the slug, the resolved appId, the auth type, and whether the slug exists
under a DIFFERENT app_id, which is the failure mode that would explain a paste
being createable and then unfindable.

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

Changes

ddiff --git a/server/pastes/routes.js b/server/pastes/routes.js
iindex 1d8fdd4..6f87e55 100644
---- a/server/pastes/routes.js
++++ b/server/pastes/routes.js
@@@ -214,8 +214,22 @@ function _rateLimitCheck(req, res) {
}
function _getPasteScoped(req, res) {
-- const paste = db.getPasteBySlug(String(req.params.slug), req.appId);
-- if (!paste) { res.status(404).json({ error: 'Paste not found' }); return null; }
++ const slug = String(req.params.slug);
++ const paste = db.getPasteBySlug(slug, req.appId);
++ if (!paste) {
++ // "Paste not found" was being reported for pastes that demonstrably exist, and the
++ // 404 was silent — so there was no way to tell whether the slug was wrong, the
++ // tenant scope was wrong, or the row was genuinely missing. Log all three.
++ let existsElsewhere = null;
++ try {
++ const any = db.get('SELECT app_id FROM pastes WHERE slug = ?', [slug]);
++ existsElsewhere = any ? any.app_id : null;
++ } catch { /* */ }
++ console.warn(`[Pastes] 404 slug="${slug}" appId="${req.appId}" auth=${req.authType || 'none'}` +
++ (existsElsewhere ? ` — EXISTS under app_id="${existsElsewhere}" (tenant mismatch)` : ' — no row with that slug'));
++ res.status(404).json({ error: 'Paste not found' });
++ return null;
++ }
return paste;
}