{"record":{"id":"97e1d14b18f0ef59","repo":"hcengineering/platform","slug":"file-not-found","errorCode":null,"errorMessage":"file not found","messagePattern":"file not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/drive/src/utils.ts","lineNumber":84,"sourceCode":"    fileId,\n    drive.class.File,\n    'versions',\n    { ...data, version },\n    versionId\n  )\n\n  return fileId\n}\n\n/** @public */\nexport async function createFileVersion (\n  client: TxOperations,\n  file: Ref<File>,\n  data: Omit<AttachedData<FileVersion>, 'version'>\n): Promise<void> {\n  const current = await client.findOne(drive.class.File, { _id: file })\n  if (current === undefined) {\n    throw new Error('file not found')\n  }\n\n  const incResult = await client.update(current, { $inc: { version: 1 } }, true)\n  const version = (incResult as any).object.version\n\n  const ops = client.apply(file)\n\n  const versionId = await ops.addCollection(\n    drive.class.FileVersion,\n    current.space,\n    current._id,\n    current._class,\n    'versions',\n    { ...data, version }\n  )\n\n  await ops.update(current, { file: versionId })\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/drive/src/utils.ts#L66-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"Uploading a new version to a file another user just deleted; offline queue replaying version uploads for removed files; automation scripts using cached ids.","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"],"exampleFix":"// before\nawait createFileVersion(client, fileRef, data)\n// after\nconst current = await client.findOne(drive.class.File, { _id: fileRef })\nif (current === undefined) throw new Error('File was deleted; cannot create version')\nawait createFileVersion(client, fileRef, data)","handlingStrategy":"validation","validationCode":"const current = await client.findOne(drive.class.File, { _id: file })\nif (current === undefined) {\n  throw new Error('File no longer exists; cannot create a version')\n}","typeGuard":"async function fileExists(client: TxOperations, file: Ref<File>): Promise<boolean> {\n  return (await client.findOne(drive.class.File, { _id: file })) !== undefined\n}","tryCatchPattern":"try {\n  await createFileVersion(client, fileRef, data)\n} catch (err) {\n  if (err.message === 'file not found') {\n    notifyUser('File was deleted; version upload aborted')\n    return\n  }\n  throw err\n}","preventionTips":["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"],"tags":["drive","file","missing-document"],"backgroundTag":"document-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}