hcengineering/platform · error
file not found
Error message
file not found
What it means
createFileVersion loads the current File by _id before appending a new version; if the file does not exist it throws 'file not found'. Version increments and version docs depend on the existing file record, so a missing file aborts the operation.
Source
Thrown at plugins/drive/src/utils.ts:84
fileId,
drive.class.File,
'versions',
{ ...data, version },
versionId
)
return fileId
}
/** @public */
export async function createFileVersion (
client: TxOperations,
file: Ref<File>,
data: Omit<AttachedData<FileVersion>, 'version'>
): Promise<void> {
const current = await client.findOne(drive.class.File, { _id: file })
if (current === undefined) {
throw new Error('file not found')
}
const incResult = await client.update(current, { $inc: { version: 1 } }, true)
const version = (incResult as any).object.version
const ops = client.apply(file)
const versionId = await ops.addCollection(
drive.class.FileVersion,
current.space,
current._id,
current._class,
'versions',
{ ...data, version }
)
await ops.update(current, { file: versionId })
View on GitHub (pinned to 63e28dc964)
Solutions
- Re-fetch the file before uploading a new version and recreate it if deleted
- Catch the error and notify the user the file no longer exists
- Avoid deleting files while version uploads are in flight (soft-delete instead)
- Fix id plumbing so the correct existing File ref is passed
Example fix
// before
await createFileVersion(client, fileRef, data)
// after
const current = await client.findOne(drive.class.File, { _id: fileRef })
if (current === undefined) throw new Error('File was deleted; cannot create version')
await createFileVersion(client, fileRef, data) Defensive patterns
Strategy: validation
Validate before calling
const current = await client.findOne(drive.class.File, { _id: file })
if (current === undefined) {
throw new Error('File no longer exists; cannot create a version')
} Type guard
async function fileExists(client: TxOperations, file: Ref<File>): Promise<boolean> {
return (await client.findOne(drive.class.File, { _id: file })) !== undefined
} Try / catch
try {
await createFileVersion(client, fileRef, data)
} catch (err) {
if (err.message === 'file not found') {
notifyUser('File was deleted; version upload aborted')
return
}
throw err
} Prevention
- Re-fetch the file before each version upload
- Use soft-delete for files with active uploads
- Validate cached refs before replaying queued uploads
- Coordinate deletes with in-flight version operations
When it happens
Trigger: Calling createFileVersion with a ref to a File that was deleted or never created; stale ref after concurrent deletion; wrong-space or wrong-type id passed.
Common situations: Uploading a new version to a file another user just deleted; offline queue replaying version uploads for removed files; automation scripts using cached ids.
Related errors
- File not found, _id: ${ref}
- Folder not found, _id: ${ref}
- Cannot resolve a ProjectDocument for document ${document._id
- parent not found
- Document not found: ${JSON.stringify(query)}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/97e1d14b18f0ef59.
Report an issue: GitHub.