hcengineering/platform · error

File not found, _id

Error message

File not found, _id: ${ref}

What it means

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.

Solutions

  1. Check the File still exists (client.findOne) before rendering its title
  2. Catch the error and render a placeholder like '(deleted file)' instead of failing the UI
  3. Purge references to deleted files from feeds/notifications
  4. Ensure the correct provider (File vs Folder) and ref are used

Example fix

// before
const title = await FileTitleProvider(client, ref)
// after
const file = await client.findOne(drive.class.File, { _id: ref })
const title = file ? file.title : '(deleted file)'
Defensive patterns

Strategy: fallback

Validate before calling

const file = doc ?? await client.findOne(drive.class.File, { _id: ref })
if (file === undefined) return '(deleted file)'

Type guard

async function fileExists(client: Client, ref: Ref<File>): Promise<boolean> {
  return (await client.findOne(drive.class.File, { _id: ref })) !== undefined
}

Try / catch

try {
  return await FileTitleProvider(client, ref, doc)
} catch (err) {
  if (err.message.startsWith('File not found')) {
    return '(deleted file)'
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/aa8acce6bc3e82c9. Report an issue: GitHub.

Appendix: source

Thrown at plugins/drive-resources/src/index.ts:253

export async function CanDeleteFolder (doc: Folder | Folder[] | undefined): Promise<boolean> {
  if (doc === undefined) return false
  doc = Array.isArray(doc) ? doc : [doc]

  const permissions = get(permissionsStore)
  const results = await Promise.all(
    doc.map(async (p) => {
      return permissions.restrictedSpaces.has(p.space)
        ? canRemoveDoc(drive.class.Folder, p.space, permissions)
        : await canDeleteObject(doc)
    })
  )
  return results.every(Boolean)
}

export async function FileTitleProvider (client: Client, ref: Ref<File>, doc?: File): Promise<string> {
  const object = doc ?? (await client.findOne(drive.class.File, { _id: ref }))
  if (object === undefined) throw new Error(`File not found, _id: ${ref}`)
  return object.title
}

export async function FolderTitleProvider (client: Client, ref: Ref<Folder>, doc?: Folder): Promise<string> {
  const object = doc ?? (await client.findOne(drive.class.Folder, { _id: ref }))
  if (object === undefined) throw new Error(`Folder not found, _id: ${ref}`)
  return object.title
}

export default async (): Promise<Resources> => ({
  component: {
    CreateDrive,
    DrivePanel,
    DriveSpaceHeader,
    DriveSpacePresenter,
    DrivePresenter,
    EditFile,
    EditFolder,

View on GitHub (pinned to 63e28dc964)