{"record":{"id":"aa8acce6bc3e82c9","repo":"hcengineering/platform","slug":"file-not-found-id-ref","errorCode":null,"errorMessage":"File not found, _id: ${ref}","messagePattern":"File not found, _id: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/drive-resources/src/index.ts","lineNumber":253,"sourceCode":"\nexport async function CanDeleteFolder (doc: Folder | Folder[] | undefined): Promise<boolean> {\n  if (doc === undefined) return false\n  doc = Array.isArray(doc) ? doc : [doc]\n\n  const permissions = get(permissionsStore)\n  const results = await Promise.all(\n    doc.map(async (p) => {\n      return permissions.restrictedSpaces.has(p.space)\n        ? canRemoveDoc(drive.class.Folder, p.space, permissions)\n        : await canDeleteObject(doc)\n    })\n  )\n  return results.every(Boolean)\n}\n\nexport async function FileTitleProvider (client: Client, ref: Ref<File>, doc?: File): Promise<string> {\n  const object = doc ?? (await client.findOne(drive.class.File, { _id: ref }))\n  if (object === undefined) throw new Error(`File not found, _id: ${ref}`)\n  return object.title\n}\n\nexport async function FolderTitleProvider (client: Client, ref: Ref<Folder>, doc?: Folder): Promise<string> {\n  const object = doc ?? (await client.findOne(drive.class.Folder, { _id: ref }))\n  if (object === undefined) throw new Error(`Folder not found, _id: ${ref}`)\n  return object.title\n}\n\nexport default async (): Promise<Resources> => ({\n  component: {\n    CreateDrive,\n    DrivePanel,\n    DriveSpaceHeader,\n    DriveSpacePresenter,\n    DrivePresenter,\n    EditFile,\n    EditFolder,","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/drive-resources/src/index.ts#L235-L271","documentation":"FileTitleProvider resolves a File title by _id, optionally using the supplied doc; if neither the doc is provided nor findOne finds the object, it throws. This prevents title providers from returning undefined titles for deleted or invalid references.","triggerScenarios":"Rendering a title/label for a File reference that no longer exists in drive.class.File; passing a stale or wrong-space ref; calling without doc after the file was deleted.","commonSituations":"Notifications or activity feeds referencing files deleted before rendering; concurrent deletion racing a title lookup; wrong _id type (e.g. folder id passed to file provider).","solutions":["Check the File still exists (client.findOne) before rendering its title","Catch the error and render a placeholder like '(deleted file)' instead of failing the UI","Purge references to deleted files from feeds/notifications","Ensure the correct provider (File vs Folder) and ref are used"],"exampleFix":"// before\nconst title = await FileTitleProvider(client, ref)\n// after\nconst file = await client.findOne(drive.class.File, { _id: ref })\nconst title = file ? file.title : '(deleted file)'","handlingStrategy":"fallback","validationCode":"const file = doc ?? await client.findOne(drive.class.File, { _id: ref })\nif (file === undefined) return '(deleted file)'","typeGuard":"async function fileExists(client: Client, ref: Ref<File>): Promise<boolean> {\n  return (await client.findOne(drive.class.File, { _id: ref })) !== undefined\n}","tryCatchPattern":"try {\n  return await FileTitleProvider(client, ref, doc)\n} catch (err) {\n  if (err.message.startsWith('File not found')) {\n    return '(deleted file)'\n  }\n  throw err\n}","preventionTips":["Pass the already-loaded doc to the provider to avoid extra lookups","Clean up references to deleted files in feeds/notifications","Use soft-delete for files referenced by activities","Confirm you use the File provider for file refs, not the Folder one"],"tags":["drive","missing-document","title-provider"],"backgroundTag":"document-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}