{"record":{"id":"e77afdae30a04c3d","repo":"cube-js/cube","slug":"cannot-enumerate-properties-on-instancename-th","errorCode":null,"errorMessage":"Cannot enumerate properties on ${instanceName}. The '${name}' has been cleaned up and is no longer available.","messagePattern":"Cannot enumerate properties on (.+?)\\. The '(.+?)' has been cleaned up and is no longer available\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/disposedProxy.ts","lineNumber":32,"sourceCode":"      throw new Error(\n        `Cannot set property '${String(prop)}' on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    apply(): never {\n      throw new Error(\n        `Cannot call method on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    has(_target: object, _prop: string | symbol): never {\n      throw new Error(\n        `Cannot check property existence on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    ownKeys(): never {\n      throw new Error(\n        `Cannot enumerate properties on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    getPrototypeOf(): never {\n      throw new Error(\n        `Cannot get prototype of ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    }\n  });\n}\n","sourceCodeStart":14,"sourceCodeEnd":45,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/disposedProxy.ts#L14-L45","documentation":"The `ownKeys` trap of the disposed proxy fires when code enumerates the properties of an instance that Cube has already disposed (e.g. via Object.keys, spread, JSON.stringify, or for...in). Cube throws deliberately to catch references that outlived their owner's cleanup.","triggerScenarios":"Running Object.keys()/Object.entries()/Object.assign()/JSON.stringify()/for...in over an object whose owning instance was disposed, so it is backed by the disposed proxy.","commonSituations":"Serializing or logging Cube internals (drivers, queues) after shutdown; spreading a stale reference into a new object; debugging code that inspects a disposed instance's shape.","solutions":["Stop enumerating or serializing the instance after its dispose/cleanup was invoked.","Capture the needed data (keys, snapshot) before teardown instead of after.","Clear stale references on disposal and check for null before enumerating."],"exampleFix":"// before\nserver.dispose();\nconsole.log(Object.keys(server.dataSourceStorage)); // throws\n\n// after\nconst keys = Object.keys(server.dataSourceStorage);\nserver.dispose();\nconsole.log(keys);","handlingStrategy":"try-catch","validationCode":"if (objRef == null) {\n  throw new Error('Cannot enumerate a cleared reference.');\n}","typeGuard":"function isEnumerable<T extends object>(ref: T | null | undefined): ref is T {\n  if (ref == null) return false;\n  try {\n    Object.keys(ref);\n    return true;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"let keys: string[];\ntry {\n  keys = Object.keys(maybeDisposed);\n} catch (e) {\n  if (e.message.includes('has been cleaned up')) {\n    keys = []; // or skip serialization entirely\n  } else {\n    throw e;\n  }\n}","preventionTips":["Snapshot data (keys, values) you need before calling dispose().","Skip serialization/logging of internals once teardown has started.","Set disposed references to null and check before spreading or stringify-ing them.","Use structured logging of explicit fields rather than dumping whole objects."],"tags":["disposed-object","lifecycle","proxy","cleanup"],"backgroundTag":"use-after-dispose","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}