eyaltoledano/claude-task-master · error
itemValidator must be a function
Error message
itemValidator must be a function
What it means
The itemValidator option must be a callable used to filter/validate parsed items (the library defaults to a validator requiring a non-empty title string). The constructor throws if itemValidator is truthy but not a function.
Source
Thrown at src/utils/stream-parser.js:83
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) {
this.onProgress = config.onProgress;
this.onError = config.onError;
this.estimateTokens = config.estimateTokens;View on GitHub (pinned to c0c98d367c)
Solutions
- Pass a predicate function: itemValidator: (item) => typeof item?.id === 'string'.
- If using a schema, wrap it: itemValidator: (item) => schema.safeParse(item).success.
- Remove the option to use the built-in defaultItemValidator.
Example fix
// before
new StreamParser({ jsonPaths: ['$.items'], itemValidator: itemSchema })
// after
new StreamParser({ jsonPaths: ['$.items'], itemValidator: (item) => itemSchema.safeParse(item).success }) Defensive patterns
Strategy: type-guard
Validate before calling
if (options.itemValidator != null && typeof options.itemValidator !== 'function') {
throw new TypeError('itemValidator must be a function');
} Type guard
function isPredicate(v) {
return typeof v === 'function';
} Try / catch
try {
return new StreamParser(options);
} catch (err) {
if (err.message === 'itemValidator must be a function') {
return new StreamParser({ ...options, itemValidator: (item) => Boolean(item && item.title) });
}
throw err;
} Prevention
- Wrap schema libraries in predicate functions: (item) => schema.safeParse(item).success.
- Verify items shape matches the validator (default expects item.title as non-empty string).
- Keep item shape and validator in sync via a shared type.
When it happens
Trigger: new StreamParser({ jsonPaths: ['$.items'], itemValidator: true }) or itemValidator set to a schema object/Zod schema instead of a predicate function.
Common situations: Passing a Zod/Joi schema object expecting the parser to integrate it natively; passing a validator name string; copy-paste from a library whose validator option accepts schemas.
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
- onProgress must be a function
- onError must be a function
- fallbackItemExtractor must be a function
- MISSING_CONFIGURATION
- INVALID_INPUT
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/63d5a003902fe59f.
Report an issue: GitHub.