{"record":{"id":"58d92326a653e0d0","repo":"mckaywrigley/chatbot-ui","slug":"message-not-found","errorCode":null,"errorMessage":"Message not found","messagePattern":"Message not found","errorType":"exception","errorClass":"Error","httpStatus":404,"severity":"warning","filePath":"db/messages.ts","lineNumber":12,"sourceCode":"import { supabase } from \"@/lib/supabase/browser-client\"\nimport { TablesInsert, TablesUpdate } from \"@/supabase/types\"\n\nexport const getMessageById = async (messageId: string) => {\n  const { data: message } = await supabase\n    .from(\"messages\")\n    .select(\"*\")\n    .eq(\"id\", messageId)\n    .single()\n\n  if (!message) {\n    throw new Error(\"Message not found\")\n  }\n\n  return message\n}\n\nexport const getMessagesByChatId = async (chatId: string) => {\n  const { data: messages } = await supabase\n    .from(\"messages\")\n    .select(\"*\")\n    .eq(\"chat_id\", chatId)\n\n  if (!messages) {\n    throw new Error(\"Messages not found\")\n  }\n\n  return messages\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/mckaywrigley/chatbot-ui/blob/81328b61d2a4ab597a7a057be70e785cf756d9f8/db/messages.ts#L1-L30","documentation":"A domain-level 'Message not found' error thrown when getMessageById's .single() select returns null. Unlike the supabase errors elsewhere, this is the app's own message: either the message id doesn't exist, was deleted, or is hidden by RLS for the current user (which makes an existing row look missing).","triggerScenarios":"Calling getMessageById with a deleted/nonexistent id, a message belonging to another user's chat under RLS, or an id held in stale client state after switching workspaces/accounts.","commonSituations":"Deep links to removed messages, retrying an action after the message was deleted in another session, RLS chat policies hiding rows, switching accounts without clearing cached message ids.","solutions":["Treat this as an expected 404: catch it and show 'message unavailable' instead of an error boundary","Verify the message id exists in the messages table for that user before calling","Check RLS SELECT policies on messages if the message should be visible","Invalidate cached message ids on account/workspace switch"],"exampleFix":"// before\ntry {\n  const message = await getMessageById(messageId)\n} catch (e) { /* generic error */ }\n\n// after\ntry {\n  const message = await getMessageById(messageId)\n} catch (e) {\n  if (e instanceof Error && e.message === \"Message not found\") {\n    return notFoundResponse(messageId)\n  }\n  throw e\n}","handlingStrategy":"try-catch","validationCode":"const { data } = await supabase.from(\"messages\").select(\"id\").eq(\"id\", messageId).maybeSingle()\nif (!data.data) return notFoundResponse()","typeGuard":"function isMessageNotFound(e: unknown): e is Error {\n  return e instanceof Error && e.message === \"Message not found\"\n}","tryCatchPattern":"try { return await getMessageById(messageId) }\ncatch (e) {\n  if (isMessageNotFound(e)) return notFound()\n  throw e\n}","preventionTips":["Cache and validate message ids before use","Clear stale ids on account/workspace switch","Check RLS policies if a visible message reports missing"],"tags":["not-found","message","supabase","rls","domain-error"],"backgroundTag":"record-not-found","analyzedSha":"81328b61d2a4ab597a7a057be70e785cf756d9f8","analyzedAt":"2026-08-27T19:24:42.689Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}