supabase/supabase · error · Error
Snippet named "${updates.name ?? foundSnippet.name}" already
Error message
Snippet named "${updates.name ?? foundSnippet.name}" already exists in the specified folder What it means
updateSnippet computes the target deterministic id from the (new folder_id, new name) and checks whether a different file already occupies that slot. If so — e.g. renaming 'a.sql' to 'b.sql' when 'b.sql' exists — it refuses the overwrite. This prevents data loss from a rename/move onto an existing file.
Source
Thrown at apps/studio/lib/api/snippets.utils.ts:421
(entry): entry is FilesystemEntry & { type: 'file'; content: string } => entry.type === 'file'
)
.find((s) => s.id === id)
if (!foundSnippet) {
throw new Error(`Snippet with id ${id} not found`)
}
const newId = generateDeterministicUuid([
updates.folder_id !== undefined ? updates.folder_id : foundSnippet.folderId,
`${updates.name ?? foundSnippet.name}.sql`,
])
const snippetAtTargetLocation = entries.find(
(entry) => entry.id === newId && entry.type === 'file'
)
if (snippetAtTargetLocation && snippetAtTargetLocation.id !== foundSnippet.id) {
throw new Error(
`Snippet named "${updates.name ?? foundSnippet.name}" already exists in the specified folder`
)
}
const snippet = buildSnippet(
foundSnippet.name,
foundSnippet.content || '',
foundSnippet.folderId,
foundSnippet.createdAt
)
// it's easier to delete the old file first and then recreate a new one
await deleteSnippet(snippet.id)
const updatedSnippet = await saveSnippet({
name: updates.name ?? snippet.name,
content: updates.content ?? snippet.content,
// folder_id can be nullView on GitHub (pinned to beee91b9c2)
Solutions
- Before applying, check the target folder for a name clash and prompt the user to overwrite or pick a new name.
- If overwrite is intended, delete the target snippet first, then update.
- Catch the error and return 409 Conflict with the colliding name so the client can react.
Example fix
// before
await updateSnippet(id, { name: newName })
// after
const targetId = generateDeterministicUuid([folderId, `${newName}.sql`])
const clash = (await getFilesystemEntries()).find(e => e.id === targetId && e.type === 'file')
if (clash && clash.id !== id) {
throw new HttpError(409, `A snippet named ${newName} already exists there`)
}
await updateSnippet(id, { name: newName }) Defensive patterns
Strategy: validation
Validate before calling
import { generateDeterministicUuid } from './snippets.browser'
const targetId = generateDeterministicUuid([
updates.folder_id ?? foundSnippet.folderId,
`${updates.name ?? foundSnippet.name}.sql`,
])
const clash = (await getFilesystemEntries({ includeContent: false }))
.find(e => e.id === targetId && e.type === 'file' && e.id !== id)
if (clash) throw new Error('Target name already in use') Type guard
const hasNameClash = async (folderId: string | null, name: string, exceptId: string): Promise<boolean> => {
const targetId = generateDeterministicUuid([folderId, `${name}.sql`])
return (await getFilesystemEntries({ includeContent: false }))
.some(e => e.id === targetId && e.type === 'file' && e.id !== exceptId)
} Try / catch
try {
await updateSnippet(id, { name: newName })
} catch (e) {
if (e instanceof Error && e.message.includes('already exists in the specified folder')) {
return res.status(409).json({ error: { message: 'A snippet with that name already exists there' } })
}
throw e
} Prevention
- Pre-check the target folder for a name clash before applying a rename/move.
- Prompt the user to overwrite or pick a new name when a clash exists.
- Return 409 at the route boundary for collisions.
When it happens
Trigger: A PATCH /content/:id that changes name and/or folder_id such that the resulting path collides with another existing snippet in the same folder. Two snippets cannot share a filename.
Common situations: User renames a snippet to a name already in use; user moves a snippet into a folder containing a same-named snippet; bulk rename creates a collision.
Related errors
- Snippet with id ${snippet.id} already exists
- Folder with name ${folderName} already exists
- Invalid name: path traversal or null bytes detected
- SNIPPETS_MANAGEMENT_FOLDER env var is not set. Please set it
- Snippet with id ${snippetId} not found
AI-assisted analysis of supabase/supabase@beee91b9c2 (2026-08-12).
Data as JSON: /api/errors/8499c77cf85db925.
Report an issue: GitHub.