{"record":{"id":"98cf86e38557139a","repo":"mckaywrigley/chatbot-ui","slug":"error-message-98cf86","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"db/chats.ts","lineNumber":22,"sourceCode":"export const getChatById = async (chatId: string) => {\n  const { data: chat } = await supabase\n    .from(\"chats\")\n    .select(\"*\")\n    .eq(\"id\", chatId)\n    .maybeSingle()\n\n  return chat\n}\n\nexport const getChatsByWorkspaceId = async (workspaceId: string) => {\n  const { data: chats, error } = await supabase\n    .from(\"chats\")\n    .select(\"*\")\n    .eq(\"workspace_id\", workspaceId)\n    .order(\"created_at\", { ascending: false })\n\n  if (!chats) {\n    throw new Error(error.message)\n  }\n\n  return chats\n}\n\nexport const createChat = async (chat: TablesInsert<\"chats\">) => {\n  const { data: createdChat, error } = await supabase\n    .from(\"chats\")\n    .insert([chat])\n    .select(\"*\")\n    .single()\n\n  if (error) {\n    throw new Error(error.message)\n  }\n\n  return createdChat\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/mckaywrigley/chatbot-ui/blob/81328b61d2a4ab597a7a057be70e785cf756d9f8/db/chats.ts#L4-L40","documentation":"Selecting chats for a workspace returned an error. PostgREST queries normally return an empty array on success, so a thrown error here means a transport/API failure, bad column reference, or RLS misconfiguration rather than 'no chats found'.","triggerScenarios":"Calling getChatsByWorkspaceId with a workspace that doesn't matter (empty array is fine) — the error path fires on network failure, a renamed/dropped column in .select/.order, or an RLS policy that errors instead of filtering.","commonSituations":"Renaming created_at or workspace_id in a migration without updating this query, stale generated Supabase types after schema change, or network/DNS issues against the Supabase project URL.","solutions":["Verify the chats table still has workspace_id and created_at columns","Confirm the Supabase URL and anon key are correct and the project is reachable","Guard on `if (error)` instead of `!chats` so empty results aren't misreported","Check Supabase dashboard logs for the failing request"],"exampleFix":"// before\nif (!chats) {\n  throw new Error(error.message)\n}\n// after\nif (error) {\n  throw new Error(error.message)\n}\nreturn chats","handlingStrategy":"try-catch","validationCode":"if (!workspaceId) throw new Error(\"workspaceId is required\");","typeGuard":"const isChat = (c: unknown): c is Tables<\"chats\"> => typeof c === \"object\" && c !== null && \"id\" in c;","tryCatchPattern":"try { return await getChatsByWorkspaceId(workspaceId) } catch (e) { if (e instanceof Error && /relation|column/i.test(e.message)) console.error(\"Schema mismatch:\", e.message); return [] }","preventionTips":["Treat empty result as [] not an error","Keep generated Supabase types in sync after migrations","Monitor Supabase status for outages"],"tags":["supabase","postgrest","select","chats","rls","network"],"backgroundTag":"supabase-query-failed","analyzedSha":"81328b61d2a4ab597a7a057be70e785cf756d9f8","analyzedAt":"2026-08-27T19:24:42.689Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}