{"record":{"id":"b16a169f1a484141","repo":"ruvnet/ruflo","slug":"plugin-this-metadata-name-not-initialized","errorCode":null,"errorMessage":"Plugin ${this.metadata.name} not initialized","messagePattern":"Plugin (.+?) not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/core/base-plugin.ts","lineNumber":111,"sourceCode":"  // =========================================================================\n\n  get state(): PluginLifecycleState {\n    return this._state;\n  }\n\n  protected setState(state: PluginLifecycleState): void {\n    const previousState = this._state;\n    this._state = state;\n    this.emit('stateChange', { previousState, currentState: state });\n  }\n\n  // =========================================================================\n  // Context Accessors\n  // =========================================================================\n\n  protected get context(): PluginContext {\n    if (!this._context) {\n      throw new Error(`Plugin ${this.metadata.name} not initialized`);\n    }\n    return this._context;\n  }\n\n  protected get config(): PluginConfig {\n    return this.context.config;\n  }\n\n  protected get logger(): ILogger {\n    return this.context.logger;\n  }\n\n  protected get eventBus(): IEventBus {\n    return this.context.eventBus;\n  }\n\n  protected get services(): ServiceContainer {\n    return this.context.services;","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/core/base-plugin.ts#L93-L129","documentation":"BasePlugin's this.context, this.config, and this.logger all dereference this._context, which the plugin manager sets inside initialize(context). Any access before initialize() completes (or after dispose clears it) throws 'Plugin <name> not initialized'. Since initialize() assigns _context before invoking subclass hooks, the usual culprit is code running entirely outside the lifecycle: constructors, field initializers, or methods called manually.","triggerScenarios":"A subclass reading this.config or this.logger in its constructor or in a class-field initializer; calling plugin methods directly on a manually instantiated plugin without registry.initialize(); wiring event handlers at construction time that touch this.context; using the plugin after dispose cleared the context.","commonSituations":"Manually new-ing a plugin class for testing and calling a helper without initialize; refactoring logic out of onInitialize() into the constructor; singleton plugins reused after teardown.","solutions":["Route plugins through the manager/registry lifecycle so initialize(context) runs before any method call","Move context-dependent logic (config reads, logging) out of constructors and field initializers into onInitialize()","If driving the lifecycle manually, call and await plugin.initialize(ctx) before invoking anything else on the instance"],"exampleFix":"// before\nclass MyPlugin extends BasePlugin {\n  private prefix = this.config.prefix; // throws: not initialized\n}\n\n// after\nclass MyPlugin extends BasePlugin {\n  private prefix?: string;\n  protected async onInitialize(): Promise<void> {\n    this.prefix = this.config.prefix; // context available here\n  }\n}","handlingStrategy":"validation","validationCode":"// Always complete the lifecycle before touching plugin internals:\nconst plugin = new MyPlugin();\nawait plugin.initialize(context); // sets _context\n// only now is it safe to call methods that use this.context/config/logger\n// never access context-dependent members in constructors or field initializers","typeGuard":"type Stateful = { state?: string };\n/** Duck-typed readiness check if your plugin class exposes its lifecycle state. */\nfunction isPluginReady(p: Stateful): boolean {\n  return p.state === 'initialized';\n}","tryCatchPattern":null,"preventionTips":["Keep all config/logger usage inside onInitialize() and later lifecycle methods","Do not call plugin helpers on manually instantiated plugins without initialize()","Drop context usage after dispose/teardown — _context is cleared"],"tags":["plugin","lifecycle","initialization-order","subclassing"],"backgroundTag":"not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}