mckaywrigley/chatbot-ui · warning · Error
error.message
Error message
error.message
What it means
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.
Source
Thrown at db/message-file-items.ts:17
import { supabase } from "@/lib/supabase/browser-client"
import { TablesInsert } from "@/supabase/types"
export const getMessageFileItemsByMessageId = async (messageId: string) => {
const { data: messageFileItems, error } = await supabase
.from("messages")
.select(
`
id,
file_items (*)
`
)
.eq("id", messageId)
.single()
if (!messageFileItems) {
throw new Error(error.message)
}
return messageFileItems
}
export const createMessageFileItems = async (
messageFileItems: TablesInsert<"message_file_items">[]
) => {
const { data: createdMessageFileItems, error } = await supabase
.from("message_file_items")
.insert(messageFileItems)
.select("*")
if (!createdMessageFileItems) {
throw new Error(error.message)
}
return createdMessageFileItemsView on GitHub (pinned to 81328b61d2)
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
Example fix
// before
if (!messageFileItems) {
throw new Error(error.message)
}
// after
if (!messageFileItems) {
if (error && error.code !== "PGRST116") throw new Error(`Query failed: ${error.message}`)
return []
} Defensive patterns
Strategy: fallback
Validate before calling
const { data: msg } = await supabase.from("messages").select("id").eq("id", messageId).maybeSingle()
if (!msg.data) return [] // message gone → no file items Type guard
const isPostgrestNotFound = (e: unknown) => e instanceof Error && /PGRST116|no rows|not found/i.test(e.message)
Try / catch
try { return await getMessageFileItemsByMessageId(messageId) }
catch (e) { if (isPostgrestNotFound(e)) return []; throw e } Prevention
- Treat missing message file items as an empty list
- Use maybeSingle + default [] for optional joins
- Ensure SELECT policies cover joined tables
When it happens
Trigger: 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.
Common situations: Chat history referencing deleted messages after cleanup jobs, RLS enabled on message_file_items without a SELECT policy, expired JWT during long chats.
Related errors
AI-assisted analysis of mckaywrigley/chatbot-ui@81328b61d2 (2026-08-27).
Data as JSON: /api/errors/3dad9d2881626509.
Report an issue: GitHub.