{"record":{"id":"3dad9d2881626509","repo":"mckaywrigley/chatbot-ui","slug":"error-message-3dad9d","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"db/message-file-items.ts","lineNumber":17,"sourceCode":"import { supabase } from \"@/lib/supabase/browser-client\"\nimport { TablesInsert } from \"@/supabase/types\"\n\nexport const getMessageFileItemsByMessageId = async (messageId: string) => {\n  const { data: messageFileItems, error } = await supabase\n    .from(\"messages\")\n    .select(\n      `\n      id,\n      file_items (*)\n    `\n    )\n    .eq(\"id\", messageId)\n    .single()\n\n  if (!messageFileItems) {\n    throw new Error(error.message)\n  }\n\n  return messageFileItems\n}\n\nexport const createMessageFileItems = async (\n  messageFileItems: TablesInsert<\"message_file_items\">[]\n) => {\n  const { data: createdMessageFileItems, error } = await supabase\n    .from(\"message_file_items\")\n    .insert(messageFileItems)\n    .select(\"*\")\n\n  if (!createdMessageFileItems) {\n    throw new Error(error.message)\n  }\n\n  return createdMessageFileItems","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/mckaywrigley/chatbot-ui/blob/81328b61d2a4ab597a7a057be70e785cf756d9f8/db/message-file-items.ts#L1-L35","documentation":"Thrown from getMessageFileItemsByMessageId when the .single() select returns no row. error.message is typically PostgREST PGRST116 ('no rows returned') when the message id doesn't exist or isn't visible under RLS, or a permission/connection message for real failures. Because the query selects by message id with joined file-item data, an unreadable joined row can also empty the result.","triggerScenarios":"Fetching file items for a message that was deleted, a message in another user's chat (RLS filters it), missing SELECT policies on message_file_items or joined tables, or an invalid uuid string.","commonSituations":"Chat history referencing deleted messages after cleanup jobs, RLS enabled on message_file_items without a SELECT policy, expired JWT during long chats.","solutions":["Handle PGRST116 as 'no file items' (return empty array) rather than throwing","Verify SELECT policies on message_file_items and joined file items/chunks tables","Validate messageId format and existence before querying","Refresh auth session in long-lived clients"],"exampleFix":"// before\nif (!messageFileItems) {\n  throw new Error(error.message)\n}\n\n// after\nif (!messageFileItems) {\n  if (error && error.code !== \"PGRST116\") throw new Error(`Query failed: ${error.message}`)\n  return []\n}","handlingStrategy":"fallback","validationCode":"const { data: msg } = await supabase.from(\"messages\").select(\"id\").eq(\"id\", messageId).maybeSingle()\nif (!msg.data) return [] // message gone → no file items","typeGuard":"const isPostgrestNotFound = (e: unknown) =>\n  e instanceof Error && /PGRST116|no rows|not found/i.test(e.message)","tryCatchPattern":"try { return await getMessageFileItemsByMessageId(messageId) }\ncatch (e) { if (isPostgrestNotFound(e)) return []; throw e }","preventionTips":["Treat missing message file items as an empty list","Use maybeSingle + default [] for optional joins","Ensure SELECT policies cover joined tables"],"tags":["supabase","postgrest","not-found","single-row","rls"],"backgroundTag":"postgrest-single-row-not-found","analyzedSha":"81328b61d2a4ab597a7a057be70e785cf756d9f8","analyzedAt":"2026-08-27T19:24:42.689Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}