eyaltoledano/claude-task-master · error · Error

Provider name must be a non-empty string

Error message

Provider name must be a non-empty string

What it means

registerProvider() is the registration entry point of the provider registry singleton. It first validates that the provider name key is a truthy, non-empty string, since the name is used as the Map key for lookup and must support getProvider(name) calls. Empty strings, non-strings, and undefined are all rejected with this error.

Source

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

	initialize() {
		if (this._initialized) {
			return this;
		}

		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,

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass a non-empty string as the first argument, e.g. registry.registerProvider('openai', provider, options).
  2. If the name comes from config/env, default or validate it first: const name = process.env.AI_PROVIDER || 'openai'.
  3. Check argument order — a provider object passed first will hit this error.
  4. Use registerRemoteProvider if you want the registry to resolve the name for you.

Example fix

// before
const name = process.env.AI_PROVIDER; // may be undefined
registry.registerProvider(name, provider);
// after
const name = process.env.AI_PROVIDER;
if (!name) throw new Error('AI_PROVIDER env var is required');
registry.registerProvider(name, provider);
Defensive patterns

Strategy: validation

Validate before calling

function assertProviderName(name) {
  if (typeof name !== 'string' || name.length === 0) {
    throw new TypeError(`providerName must be a non-empty string, got: ${JSON.stringify(name)}`);
  }
}
assertProviderName(name);
registry.registerProvider(name, provider, options);

Type guard

const isValidProviderName = (n) => typeof n === 'string' && n.trim().length > 0;

Try / catch

try {
  registry.registerProvider(name, provider, options);
} catch (err) {
  if (err.message.startsWith('Provider name must be')) {
    throw new Error(`Invalid provider name "${name}" — check AI_PROVIDER config`);
  }
  throw err;
}

Prevention

When it happens

Trigger: registerProvider('', provider), registerProvider(null, provider), registerProvider(undefined, provider), registerProvider(123, provider), or registerProvider(config.providerName, provider) where config.providerName is unset/empty.

Common situations: Reading the provider name from environment variables or config files that are missing (e.g. unset AI_PROVIDER env var); typos in config keys yielding empty strings; passing an options object positionally so the provider lands in the name slot.

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/ab5ca270a24c298c. Report an issue: GitHub.