{"record":{"id":"adb3cc893c5f1b44","repo":"eyaltoledano/claude-task-master","slug":"provider-instance-is-required","errorCode":null,"errorMessage":"Provider instance is required","messagePattern":"Provider instance is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/provider-registry/index.js","lineNumber":61,"sourceCode":"\n\t\tthis._initialized = true;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Register a provider with the registry\n\t * @param {string} providerName - The name of the provider\n\t * @param {object} provider - The provider instance\n\t * @param {object} options - Additional options for registration\n\t * @returns {ProviderRegistry} The singleton instance for chaining\n\t */\n\tregisterProvider(providerName, provider, options = {}) {\n\t\tif (!providerName || typeof providerName !== 'string') {\n\t\t\tthrow new Error('Provider name must be a non-empty string');\n\t\t}\n\n\t\tif (!provider) {\n\t\t\tthrow new Error('Provider instance is required');\n\t\t}\n\n\t\t// Validate that provider implements the required interface\n\t\tif (\n\t\t\ttypeof provider.generateText !== 'function' ||\n\t\t\ttypeof provider.streamText !== 'function' ||\n\t\t\ttypeof provider.generateObject !== 'function'\n\t\t) {\n\t\t\tthrow new Error('Provider must implement BaseAIProvider interface');\n\t\t}\n\n\t\t// Add provider to the registry\n\t\tthis._providers.set(providerName, {\n\t\t\tinstance: provider,\n\t\t\toptions,\n\t\t\tregisteredAt: new Date()\n\t\t});\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/src/provider-registry/index.js#L43-L79","documentation":"After validating the name, registerProvider() checks that an actual provider instance was supplied. The registry stores the instance for later retrieval and delegation, so a falsy value (undefined, null, false, 0) cannot be registered. This typically means the provider failed to instantiate or was never created.","triggerScenarios":"registerProvider('openai'), registerProvider('openai', null), registerProvider(name, getConfiguredProvider()) where the factory returned undefined/null due to a failed init or missing API key.","commonSituations":"A lazy provider factory returning undefined when required options (API keys) are missing; forgetting to import/instantiate the provider class (passing the class's module namespace or a bad import); conditional initialization skipped at startup.","solutions":["Instantiate the provider before registering: registry.registerProvider('openai', new OpenAIProvider(config)).","Check the return value of any provider factory — if it can return null/undefined, guard before registering.","Verify the import is correct; passing a module object instead of an instance can be falsy or fail later.","Fix the missing configuration (e.g. API key) that caused the factory to skip creation."],"exampleFix":"// before\nconst provider = createProvider(config); // returns null if no key\nregistry.registerProvider('openai', provider);\n// after\nconst provider = createProvider(config);\nif (!provider) throw new Error('Failed to create OpenAI provider; check API key');\nregistry.registerProvider('openai', provider);","handlingStrategy":"validation","validationCode":"function assertProviderInstance(provider) {\n  if (provider === null || provider === undefined) {\n    throw new TypeError('provider instance is required — check that your provider factory succeeded');\n  }\n}\nconst provider = createProvider(config);\nassertProviderInstance(provider);\nregistry.registerProvider('openai', provider);","typeGuard":"const isProviderInstance = (p) => p !== null && (typeof p === 'object' || typeof p === 'function');","tryCatchPattern":"try {\n  registry.registerProvider('openai', provider);\n} catch (err) {\n  if (err.message === 'Provider instance is required') {\n    console.error('Provider creation failed — verify API keys/config for provider construction');\n    throw new Error('Provider initialization failed before registration');\n  }\n  throw err;\n}","preventionTips":["Ensure provider factories throw on failure rather than silently returning null/undefined.","Instantiate providers explicitly with new and log construction failures.","Validate required config (API keys) before provider creation.","Never pass a class reference or module namespace where an instance is expected."],"tags":["validation","provider-registry","argument-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}