eyaltoledano/claude-task-master · error

fallbackItemExtractor must be a function

Error message

fallbackItemExtractor must be a function

What it means

The fallbackItemExtractor option must be a callable used to salvage items from raw text when JSON path extraction fails. The constructor throws if the value is truthy but not a function. Fail-fast validation prevents mid-stream crashes in the fallback path.

Source

Thrown at src/utils/stream-parser.js:80

			throw new Error('maxBufferSize must be positive');
		}
		if (this.expectedTotal < 0) {
			throw new Error('expectedTotal cannot be negative');
		}
		if (this.estimateTokens && typeof this.estimateTokens !== 'function') {
			throw new Error('estimateTokens must be a function');
		}
		if (this.onProgress && typeof this.onProgress !== 'function') {
			throw new Error('onProgress must be a function');
		}
		if (this.onError && typeof this.onError !== 'function') {
			throw new Error('onError must be a function');
		}
		if (
			this.fallbackItemExtractor &&
			typeof this.fallbackItemExtractor !== 'function'
		) {
			throw new Error('fallbackItemExtractor must be a function');
		}
		if (this.itemValidator && typeof this.itemValidator !== 'function') {
			throw new Error('itemValidator must be a function');
		}
	}

	static defaultItemValidator(item) {
		return (
			item && item.title && typeof item.title === 'string' && item.title.trim()
		);
	}
}

/**
 * Manages progress tracking and metadata
 */
class ProgressTracker {
	constructor(config) {

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass a function: fallbackItemExtractor: (text) => [...text.matchAll(/\{[^}]+\}/g)].map(m => JSON.parse(m[0])).
  2. If using a regex, wrap it in a function that applies it.
  3. Remove the option to rely on default extraction behavior.

Example fix

// before
new StreamParser({ jsonPaths: ['$.items'], fallbackItemExtractor: /\{.*\}/g })
// after
new StreamParser({ jsonPaths: ['$.items'], fallbackItemExtractor: (text) => text.match(/\{.*\}/g)?.map(JSON.parse) ?? [] })
Defensive patterns

Strategy: type-guard

Validate before calling

if (options.fallbackItemExtractor != null && typeof options.fallbackItemExtractor !== 'function') {
  throw new TypeError('fallbackItemExtractor must be a function');
}

Type guard

function isExtractor(v) {
  return typeof v === 'function' && v.length <= 1;
}

Try / catch

try {
  return new StreamParser(options);
} catch (err) {
  if (err.message === 'fallbackItemExtractor must be a function') {
    const { fallbackItemExtractor, ...rest } = options;
    return new StreamParser(rest);
  }
  throw err;
}

Prevention

When it happens

Trigger: new StreamParser({ jsonPaths: ['$.items'], fallbackItemExtractor: true }) or passing a string/object (e.g. a regex or extractor descriptor) instead of a function.

Common situations: Passing a regex intended to be used for extraction (the library expects a function); config-driven wiring with serialized placeholders; copy-paste of an option name from a different library.

Understand the failure class

Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.

Related errors


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