mckaywrigley/chatbot-ui · error · Error
error.message
Error message
error.message
What it means
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.)
Source
Thrown at db/folders.ts:11
import { supabase } from "@/lib/supabase/browser-client"
import { TablesInsert, TablesUpdate } from "@/supabase/types"
export const getFoldersByWorkspaceId = async (workspaceId: string) => {
const { data: folders, error } = await supabase
.from("folders")
.select("*")
.eq("workspace_id", workspaceId)
if (!folders) {
throw new Error(error.message)
}
return folders
}
export const createFolder = async (folder: TablesInsert<"folders">) => {
const { data: createdFolder, error } = await supabase
.from("folders")
.insert([folder])
.select("*")
.single()
if (error) {
throw new Error(error.message)
}
return createdFolder
}View on GitHub (pinned to 81328b61d2)
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
Example fix
// before
if (!folders) {
throw new Error(error.message)
}
// after
if (error) throw new Error(`Failed to load folders: ${error.message} (code=${error.code})`)
return folders ?? [] Defensive patterns
Strategy: validation
Validate before calling
const { data, error } = await supabase.from("workspaces").select("id").eq("id", workspaceId).maybeSingle()
if (error || !data) return [] // invalid/inaccessible workspace → no folders Type guard
const foldersAreValid = (f: unknown): f is Tables<"folders">[] => Array.isArray(f) && f.every(x => typeof x === "object" && "id" in x)
Try / catch
try { return await getFoldersByWorkspaceId(id) }
catch (e) { console.error("folders load failed", e); return [] } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of mckaywrigley/chatbot-ui@81328b61d2 (2026-08-27).
Data as JSON: /api/errors/6bb42c9f950fbcf3.
Report an issue: GitHub.