{"record":{"id":"6bb42c9f950fbcf3","repo":"mckaywrigley/chatbot-ui","slug":"error-message-6bb42c","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"db/folders.ts","lineNumber":11,"sourceCode":"import { supabase } from \"@/lib/supabase/browser-client\"\nimport { TablesInsert, TablesUpdate } from \"@/supabase/types\"\n\nexport const getFoldersByWorkspaceId = async (workspaceId: string) => {\n  const { data: folders, error } = await supabase\n    .from(\"folders\")\n    .select(\"*\")\n    .eq(\"workspace_id\", workspaceId)\n\n  if (!folders) {\n    throw new Error(error.message)\n  }\n\n  return folders\n}\n\nexport const createFolder = async (folder: TablesInsert<\"folders\">) => {\n  const { data: createdFolder, error } = await supabase\n    .from(\"folders\")\n    .insert([folder])\n    .select(\"*\")\n    .single()\n\n  if (error) {\n    throw new Error(error.message)\n  }\n\n  return createdFolder\n}","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/mckaywrigley/chatbot-ui/blob/81328b61d2a4ab597a7a057be70e785cf756d9f8/db/folders.ts#L1-L29","documentation":"Thrown when selecting folders by workspace_id returns null data. With this query shape, a genuinely empty workspace returns an empty array (not null), so reaching this throw means an actual error occurred — most often RLS/permission failure or a connection problem — and error.message carries the PostgREST message. (Historically some supabase-js versions returned null on error, hence the guard.)","triggerScenarios":"Selecting folders with an expired JWT (RLS rejects), missing SELECT policy on folders for authenticated users, network/SUPABASE_URL misconfiguration, or a supabase-js version that returns data:null on error.","commonSituations":"Workspace loads with zero folders shown plus a console error after session expiry; env vars pointing at the wrong project; policies enabled after go-live without a folders SELECT policy.","solutions":["Check error alongside folders: if error exists, log code/message and fix policy or auth","Add a SELECT policy on folders (USING true or auth-based)","Confirm SUPABASE_URL/SUPABASE_ANON_KEY env vars and refresh the session","Treat empty array as valid (no folders) — do not throw for it"],"exampleFix":"// before\nif (!folders) {\n  throw new Error(error.message)\n}\n\n// after\nif (error) throw new Error(`Failed to load folders: ${error.message} (code=${error.code})`)\nreturn folders ?? []","handlingStrategy":"validation","validationCode":"const { data, error } = await supabase.from(\"workspaces\").select(\"id\").eq(\"id\", workspaceId).maybeSingle()\nif (error || !data) return [] // invalid/inaccessible workspace → no folders","typeGuard":"const foldersAreValid = (f: unknown): f is Tables<\"folders\">[] =>\n  Array.isArray(f) && f.every(x => typeof x === \"object\" && \"id\" in x)","tryCatchPattern":"try { return await getFoldersByWorkspaceId(id) }\ncatch (e) { console.error(\"folders load failed\", e); return [] }","preventionTips":["Return [] for empty or inaccessible workspaces instead of throwing","Monitor for expired sessions on workspace load","Keep SELECT policies present on every table after enabling RLS"],"tags":["supabase","postgrest","select","rls","folders"],"backgroundTag":"supabase-postgrest-query-error","analyzedSha":"81328b61d2a4ab597a7a057be70e785cf756d9f8","analyzedAt":"2026-08-27T19:24:42.689Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}