hcengineering/platform · error
parent not found
Error message
parent not found
What it means
createFolder resolves the requested parent Folder to build the new folder's path; if the parent is not Root and no Folder with data.parent exists, it throws 'parent not found'. This keeps the folder path chain consistent and prevents orphaned folders.
Source
Thrown at plugins/drive/src/utils.ts:33
import { type AttachedData, type Data, type Ref, type TxOperations, generateId } from '@hcengineering/core'
import { type Location } from '@hcengineering/ui'
import drive, { driveId } from './plugin'
import type { Drive, File, FileVersion, Folder } from './types'
/** @public */
export async function createFolder (
client: TxOperations,
space: Ref<Drive>,
data: Omit<Data<Folder>, 'path'>
): Promise<Ref<Folder>> {
let path: Array<Ref<Folder>> = []
if (data.parent !== drive.ids.Root) {
const parent = await client.findOne(drive.class.Folder, { _id: data.parent })
if (parent === undefined) {
throw new Error('parent not found')
}
path = [parent._id, ...parent.path]
}
return await client.createDoc(drive.class.Folder, space, { ...data, path })
}
/** @public */
export async function createFile (
client: TxOperations,
space: Ref<Drive>,
parent: Ref<Folder>,
data: Omit<AttachedData<FileVersion>, 'version'>
): Promise<Ref<File>> {
const folder = await client.findOne(drive.class.Folder, { _id: parent })
const path = folder !== undefined ? [folder._id, ...folder.path] : []
const version = 1View on GitHub (pinned to 63e28dc964)
Solutions
- Verify the parent folder exists (client.findOne on drive.class.Folder) before calling createFolder
- Re-select a valid parent in the UI after a deletion, then retry
- Handle deletions that should cascade or block subfolder creation
- Catch the error and refresh the folder tree before retrying
Example fix
// before
await createFolder(client, space, { parent: staleParentId, name })
// after
const parent = await client.findOne(drive.class.Folder, { _id: parentId })
if (parent === undefined) throw new Error('Please refresh: parent folder no longer exists')
await createFolder(client, space, { parent: parentId, name }) Defensive patterns
Strategy: validation
Validate before calling
if (data.parent !== drive.ids.Root) {
const parent = await client.findOne(drive.class.Folder, { _id: data.parent })
if (parent === undefined) {
throw new Error('Refresh the folder tree: parent no longer exists')
}
} Type guard
async function parentExists(client: Client, parent: Ref<Folder>): Promise<boolean> {
return parent === drive.ids.Root ||
(await client.findOne(drive.class.Folder, { _id: parent })) !== undefined
} Try / catch
try {
await createFolder(client, space, data)
} catch (err) {
if (err.message === 'parent not found') {
await refreshFolderTree()
// re-pick a valid parent, then retry
return
}
throw err
} Prevention
- Refresh the folder tree after any deletion
- Re-validate the selected parent id at creation time
- Block deletion of folders that have pending create operations
- Handle concurrent-delete races with a re-check before create
When it happens
Trigger: Calling createFolder with data.parent referencing a deleted or non-existent Folder; race where the parent is deleted between UI selection and creation; invalid parent id from client-side state.
Common situations: Two users concurrently: one deletes parent folder, another creates a subfolder in it; stale UI tree after deletions; import scripts with broken parent references.
Related errors
- File not found, _id: ${ref}
- Folder not found, _id: ${ref}
- file not found
- Couldn't find the parent document meta with id: ${parentDocO
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/4b0f474aa192b543.
Report an issue: GitHub.