{"record":{"id":"16b758e0a283366f","repo":"hcengineering/platform","slug":"core-status-objectnotfound","errorCode":"core.status.ObjectNotFound","errorMessage":"ObjectNotFound","messagePattern":"ObjectNotFound","errorType":"error_code","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"foundations/core/packages/core/src/memdb.ts","lineNumber":83,"sourceCode":"  private getByIdQuery<T extends Doc>(query: DocumentQuery<T>, _class: Ref<Class<T>>): T[] {\n    const result: T[] = []\n    if (typeof query._id === 'string') {\n      const obj = this.objectById.get(query._id) as T\n      if (obj !== undefined && this.hierarchy.isDerived(obj._class, _class)) result.push(obj)\n    } else if (query._id?.$in !== undefined) {\n      const ids = new Set(query._id.$in)\n      for (const id of ids) {\n        const obj = this.objectById.get(id) as T\n        if (obj !== undefined && this.hierarchy.isDerived(obj._class, _class)) result.push(obj)\n      }\n    }\n    return result\n  }\n\n  getObject<T extends Doc>(_id: Ref<T>): T {\n    const doc = this.objectById.get(_id)\n    if (doc === undefined) {\n      throw new PlatformError(new Status(Severity.ERROR, core.status.ObjectNotFound, { _id }))\n    }\n    return doc as T\n  }\n\n  findObject<T extends Doc>(_id: Ref<T>): T | undefined {\n    const doc = this.objectById.get(_id)\n    return doc as T\n  }\n\n  private async getLookupValue<T extends Doc>(\n    _class: Ref<Class<T>>,\n    doc: T,\n    lookup: Lookup<T>,\n    result: LookupData<T>\n  ): Promise<void> {\n    for (const key in lookup) {\n      if (key === '_id') {\n        await this.getReverseLookupValue(doc, lookup, result)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/packages/core/src/memdb.ts#L65-L101","documentation":"MemDb.getObject performs a synchronous in-memory lookup by document _id and throws a PlatformError with status core.status.ObjectNotFound when no object with that id exists in the database. Unlike findObject (which returns undefined), getObject treats a missing object as a hard failure.","triggerScenarios":"Calling getObject (or the doc() convenience wrapper) with an _id that was never created, was already removed, or belongs to a different db instance (e.g. fetching by a raw string id from a URL before validating existence).","commonSituations":"Stale references after a document was deleted by another user; passing query params/URL ids straight into getObject; reading from a filtered or model-only memdb that lacks the document; id typo.","solutions":["Use findObject(...) and handle undefined before calling getObject","Validate that the id exists (e.g. client.findOne) before dereferencing","Check you are querying the same db/client instance where the doc was created","Catch the PlatformError and test err.status?.code === core.status.ObjectNotFound to handle the missing case"],"exampleFix":"// before\nconst doc = db.getObject(id as Ref<Doc>)\n// after\nconst doc = db.findObject(id as Ref<Doc>)\nif (doc === undefined) {\n  throw new Error(`Document ${id} not found or deleted`)\n}","handlingStrategy":"type-guard","validationCode":"const doc = db.findObject(id)\nif (doc === undefined) {\n  // handle missing document without throwing\n  return null\n}\n// safe: doc is defined","typeGuard":"function exists<T extends Doc>(db: MemDb, id: Ref<T>): boolean {\n  return db.findObject(id) !== undefined\n}","tryCatchPattern":"try {\n  const doc = db.getObject(_id)\n  // use doc\n} catch (err: any) {\n  if (err?.status?.code === core.status.ObjectNotFound) {\n    return null // treat as missing\n  }\n  throw err\n}","preventionTips":["Prefer findObject when absence is an expected outcome","Validate URL/query-param ids against the db before dereferencing","Watch for deletes by other clients invalidating held refs","Catch core.status.ObjectNotFound explicitly rather than generic Error"],"tags":["memdb","not-found","doc-reference"],"backgroundTag":"object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}