{"record":{"id":"3809fe0cd880de42","repo":"hcengineering/platform","slug":"reference-not-found","errorCode":null,"errorMessage":"Reference not found","messagePattern":"Reference not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/packages/client/src/client.ts","lineNumber":44,"sourceCode":"import { ContainerConnectionImpl, NetworkDirectConnectionImpl, RoutedNetworkAgentConnectionImpl } from './agent'\nimport { opNames } from './types'\n\ninterface ClientAgentRecord {\n  agent: NetworkAgent\n  register: Promise<void>\n  resolve: () => void\n}\n\nclass ContainerReferenceImpl implements ContainerReference {\n  constructor (\n    readonly uuid: ContainerUuid,\n    private readonly client: NetworkClientImpl\n  ) {}\n\n  get endpoint (): ContainerEndpointRef {\n    const ref = this.client.references.get(this.uuid)\n    if (ref === undefined) {\n      throw new Error('Reference not found')\n    }\n    return ref.endpoint\n  }\n\n  async close (): Promise<void> {\n    await this.client.release(this.uuid)\n    this.client.references.delete(this.uuid)\n  }\n\n  async request (operation: string, data?: any): Promise<any> {\n    return await this.client.request(this.uuid, operation, data)\n  }\n\n  cast<T extends object>(interfaceName?: string): T {\n    return createProxy<T>(this, interfaceName)\n  }\n\n  async connect (): Promise<ContainerConnection> {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/net/packages/client/src/client.ts#L26-L62","documentation":"The container wrapper's endpoint getter looks up the container's UUID in the client's references map to expose its endpoint reference. If the UUID is absent, the reference was never established or has been released, so it throws instead of returning undefined. Accessing endpoint on a closed/released container is invalid.","triggerScenarios":"Reading container.endpoint after client.release(uuid) or container.close(); accessing endpoint on a container whose reference registration failed; passing a constructed Container object whose uuid was never registered with the client.","commonSituations":"Double-close patterns where code touches endpoint in a finally block after release; containers invalidated by endpoint-change events that dropped references; holding Container objects across reconnects.","solutions":["Do not access endpoint after close/release; capture the endpoint value earlier if needed","Re-create the container or re-acquire the reference before reading endpoint","Track container lifecycle and skip endpoint access for released UUIDs","Check references.has(uuid) before accessing endpoint"],"exampleFix":"// before\nconst ep = container.endpoint // throws if released\nawait container.close()\n// after\nconst ep = container.endpoint\nawait container.close()\n// never touch container.endpoint again; use saved ep if needed","handlingStrategy":"type-guard","validationCode":"if (client.references?.get(container.uuid) === undefined) {\n  throw new Error('Container already released')\n}","typeGuard":"function hasReference(client: NetworkClientImpl, uuid: ContainerUuid): boolean {\n  return client.references.get(uuid) !== undefined\n}","tryCatchPattern":"let ep: ContainerEndpointRef\ntry {\n  ep = container.endpoint\n} catch (e) {\n  if (e instanceof Error && e.message === 'Reference not found') {\n    ep = await reacquireEndpoint(container.uuid)\n  } else { throw e }\n}","preventionTips":["Capture endpoint before close/release","Never access container state after release","Track released UUIDs in a Set and guard accesses","Re-create containers instead of reusing released instances"],"tags":["reference","lifecycle","use-after-release"],"backgroundTag":"container-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}