eyaltoledano/claude-task-master · error · Error

Provider instance is required

Error message

Provider instance is required

What it means

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.

Source

Thrown at src/provider-registry/index.js:61

		this._initialized = true;
		return this;
	}

	/**
	 * Register a provider with the registry
	 * @param {string} providerName - The name of the provider
	 * @param {object} provider - The provider instance
	 * @param {object} options - Additional options for registration
	 * @returns {ProviderRegistry} The singleton instance for chaining
	 */
	registerProvider(providerName, provider, options = {}) {
		if (!providerName || typeof providerName !== 'string') {
			throw new Error('Provider name must be a non-empty string');
		}

		if (!provider) {
			throw new Error('Provider instance is required');
		}

		// Validate that provider implements the required interface
		if (
			typeof provider.generateText !== 'function' ||
			typeof provider.streamText !== 'function' ||
			typeof provider.generateObject !== 'function'
		) {
			throw new Error('Provider must implement BaseAIProvider interface');
		}

		// Add provider to the registry
		this._providers.set(providerName, {
			instance: provider,
			options,
			registeredAt: new Date()
		});

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Instantiate the provider before registering: registry.registerProvider('openai', new OpenAIProvider(config)).
  2. Check the return value of any provider factory — if it can return null/undefined, guard before registering.
  3. Verify the import is correct; passing a module object instead of an instance can be falsy or fail later.
  4. Fix the missing configuration (e.g. API key) that caused the factory to skip creation.

Example fix

// before
const provider = createProvider(config); // returns null if no key
registry.registerProvider('openai', provider);
// after
const provider = createProvider(config);
if (!provider) throw new Error('Failed to create OpenAI provider; check API key');
registry.registerProvider('openai', provider);
Defensive patterns

Strategy: validation

Validate before calling

function assertProviderInstance(provider) {
  if (provider === null || provider === undefined) {
    throw new TypeError('provider instance is required — check that your provider factory succeeded');
  }
}
const provider = createProvider(config);
assertProviderInstance(provider);
registry.registerProvider('openai', provider);

Type guard

const isProviderInstance = (p) => p !== null && (typeof p === 'object' || typeof p === 'function');

Try / catch

try {
  registry.registerProvider('openai', provider);
} catch (err) {
  if (err.message === 'Provider instance is required') {
    console.error('Provider creation failed — verify API keys/config for provider construction');
    throw new Error('Provider initialization failed before registration');
  }
  throw err;
}

Prevention

When it happens

Trigger: registerProvider('openai'), registerProvider('openai', null), registerProvider(name, getConfiguredProvider()) where the factory returned undefined/null due to a failed init or missing API key.

Common situations: 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.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/adb3cc893c5f1b44. Report an issue: GitHub.