{"record":{"id":"48de4f54e75f7812","repo":"hcengineering/platform","slug":"hierarchy-is-not-defined-48de4f","errorCode":null,"errorMessage":"Hierarchy is not defined","messagePattern":"Hierarchy is not defined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pods/media/src/client.ts","lineNumber":204,"sourceCode":"  async findOne<T extends Doc>(\n    _class: Ref<Class<T>>,\n    query: DocumentQuery<T>,\n    options?: FindOptions<T>\n  ): Promise<WithLookup<T> | undefined> {\n    return await this.client.findOne(_class, query, options)\n  }\n\n  async searchFulltext (query: SearchQuery, options: SearchOptions): Promise<SearchResult> {\n    return await this.client.searchFulltext(query, options)\n  }\n\n  async close (): Promise<void> {\n    // No ned to close the REST client\n  }\n\n  getHierarchy (): Hierarchy {\n    if (this.hierarchy === undefined) {\n      throw new Error('Hierarchy is not defined')\n    }\n    return this.hierarchy\n  }\n\n  getModel (): ModelDb {\n    if (this.model === undefined) {\n      throw new Error('Model is not defined')\n    }\n    return this.model\n  }\n}\n","sourceCodeStart":186,"sourceCodeEnd":216,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/pods/media/src/client.ts#L186-L216","documentation":"Plain Error thrown by MediaClient.getHierarchy when the internal hierarchy field is still undefined. getHierarchy is a non-nullable accessor — the client expects connect() (or the initialization path assigning this.hierarchy) to have run first.","triggerScenarios":"Calling client.getHierarchy() before client.connect()/init() completed, after a failed connection attempt that left hierarchy unassigned, or after close() on a client whose implementation clears state.","commonSituations":"Constructing MediaClient in one place and calling accessors in another without awaiting connect; race conditions where a consumer fires before initialization completes; tests instantiating the client without a server; forgetting to await an async init.","solutions":["Call connect()/initialize and await it before any getHierarchy()/getModel() call","Guard call sites with a connection-state check or expose an isConnected() helper","Lazily initialize the hierarchy inside getHierarchy() if the API permits","Restructure so accessors are only handed out after the client reports ready","Add an assertion/test covering the initialization order"],"exampleFix":"// before\nconst client = new MediaClient(url)\nconst hierarchy = client.getHierarchy() // throws\n// after\nconst client = new MediaClient(url)\nawait client.connect()\nconst hierarchy = client.getHierarchy()","handlingStrategy":"validation","validationCode":"if (!client.isConnected?.()) await client.connect()","typeGuard":null,"tryCatchPattern":"try {\n  const hierarchy = client.getHierarchy()\n} catch {\n  await client.connect()\n  const hierarchy = client.getHierarchy()\n}","preventionTips":["Always await connect() before accessor calls","Encapsulate client creation in an async factory returning ready clients","Assert connection state in tests","Never share a client instance before initialization completes"],"tags":["typescript","initialization","lifecycle"],"backgroundTag":"not-initialized","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}