eyaltoledano/claude-task-master · error

jsonPaths array cannot be empty

Error message

jsonPaths array cannot be empty

What it means

StreamParser.validate also requires jsonPaths to contain at least one entry. An empty array is type-correct but leaves the parser with nothing to extract, so it is rejected explicitly right after the array-type check.

Source

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

		this.onProgress = config.onProgress;
		this.onError = config.onError;
		this.estimateTokens =
			config.estimateTokens || ((text) => Math.ceil(text.length / 4));
		this.expectedTotal = config.expectedTotal || 0;
		this.fallbackItemExtractor = config.fallbackItemExtractor;
		this.itemValidator =
			config.itemValidator || StreamParserConfig.defaultItemValidator;
		this.maxBufferSize = config.maxBufferSize || DEFAULT_MAX_BUFFER_SIZE;

		this.validate();
	}

	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 &&

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Provide at least one JSON path in the array, e.g. ['choices.0.delta.content']
  2. Guard the caller: skip constructing the parser (or fall back to default paths) when the selected list is empty
  3. Give config a non-empty default instead of [].

Example fix

// before
const paths = selectedFields.filter(Boolean); // may be []
const parser = new StreamParser({ jsonPaths: paths });
// after
const paths = selectedFields.filter(Boolean);
if (paths.length === 0) return null;
const parser = new StreamParser({ jsonPaths: paths });
Defensive patterns

Strategy: validation

Validate before calling

const paths = (selectedPaths || []).filter(Boolean);
if (paths.length === 0) {
  throw new TypeError('At least one jsonPath is required to construct StreamParser');
}

Type guard

const hasPaths = (v) => Array.isArray(v) && v.length > 0;

Try / catch

try {
  const parser = new StreamParser({ jsonPaths: paths });
} catch (err) {
  if (err.message === 'jsonPaths array cannot be empty') {
    const parser = new StreamParser({ jsonPaths: ['delta.text'] }); // sensible default
  } else throw err;
}

Prevention

When it happens

Trigger: Constructing StreamParser with jsonPaths: [] — e.g. user selected no fields, a filter removed all entries, or config initialized with an empty default.

Common situations: UI/config where path selection is optional but the parser is always constructed; building jsonPaths by filtering and ending up with an empty list; env-driven config where the variable is set but parses to [].

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