eyaltoledano/claude-task-master · error

onProgress must be a function

Error message

onProgress must be a function

What it means

The onProgress option must be a callable invoked with parsing progress updates. The constructor throws if onProgress is truthy but not a function, catching wiring mistakes before streaming starts.

Source

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

	validate() {
		if (!this.jsonPaths || !Array.isArray(this.jsonPaths)) {
			throw new Error('jsonPaths is required and must be an array');
		}
		if (this.jsonPaths.length === 0) {
			throw new Error('jsonPaths array cannot be empty');
		}
		if (this.maxBufferSize <= 0) {
			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()

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass a real function: onProgress: (progress) => console.log(progress.percent).
  2. If wiring from config, resolve the callback reference before constructing.
  3. Remove onProgress if progress reporting is unnecessary.

Example fix

// before
new StreamParser({ jsonPaths: ['$.items'], onProgress: 'logProgress' })
// after
new StreamParser({ jsonPaths: ['$.items'], onProgress: (p) => console.log(`${p.parsed}/${p.total}`) })
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

function isCallable(v) {
  return typeof v === 'function';
}

Try / catch

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

Prevention

When it happens

Trigger: new StreamParser({ jsonPaths: [...], onProgress: true }), onProgress: 'updateProgress' (string), or spreading a config object where onProgress holds a serialized/non-callable value.

Common situations: Passing a callback name instead of the callback; an async wrapper imported incorrectly (module object, not function); config-driven setup where callbacks cannot be serialized.

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