{"record":{"id":"fb611ede2219df2c","repo":"eyaltoledano/claude-task-master","slug":"onerror-must-be-a-function","errorCode":null,"errorMessage":"onError must be a function","messagePattern":"onError must be a function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/stream-parser.js","lineNumber":74,"sourceCode":"\t\t\tthrow new Error('jsonPaths is required and must be an array');\n\t\t}\n\t\tif (this.jsonPaths.length === 0) {\n\t\t\tthrow new Error('jsonPaths array cannot be empty');\n\t\t}\n\t\tif (this.maxBufferSize <= 0) {\n\t\t\tthrow new Error('maxBufferSize must be positive');\n\t\t}\n\t\tif (this.expectedTotal < 0) {\n\t\t\tthrow new Error('expectedTotal cannot be negative');\n\t\t}\n\t\tif (this.estimateTokens && typeof this.estimateTokens !== 'function') {\n\t\t\tthrow new Error('estimateTokens must be a function');\n\t\t}\n\t\tif (this.onProgress && typeof this.onProgress !== 'function') {\n\t\t\tthrow new Error('onProgress must be a function');\n\t\t}\n\t\tif (this.onError && typeof this.onError !== 'function') {\n\t\t\tthrow new Error('onError must be a function');\n\t\t}\n\t\tif (\n\t\t\tthis.fallbackItemExtractor &&\n\t\t\ttypeof this.fallbackItemExtractor !== 'function'\n\t\t) {\n\t\t\tthrow new Error('fallbackItemExtractor must be a function');\n\t\t}\n\t\tif (this.itemValidator && typeof this.itemValidator !== 'function') {\n\t\t\tthrow new Error('itemValidator must be a function');\n\t\t}\n\t}\n\n\tstatic defaultItemValidator(item) {\n\t\treturn (\n\t\t\titem && item.title && typeof item.title === 'string' && item.title.trim()\n\t\t);\n\t}\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/src/utils/stream-parser.js#L56-L92","documentation":"The onError option must be a callable that receives streaming/parsing errors. The constructor throws if onError is truthy but not a function, so error-routing mistakes surface at construction time rather than when an error actually occurs.","triggerScenarios":"new StreamParser({ jsonPaths: [...], onError: true }), onError: 'handleError' (string name), or onError set to an object like an EventEmitter or logger instance instead of a function.","commonSituations":"Passing a logger object intending the parser to call logger.error; passing a method reference extracted incorrectly; JSON-defined options carrying placeholder strings.","solutions":["Pass a function: onError: (err) => console.error(err).","If you have a logger, wrap it: onError: (err) => logger.error(err).","Remove onError if the default error propagation is acceptable."],"exampleFix":"// before\nnew StreamParser({ jsonPaths: ['$.items'], onError: logger })\n// after\nnew StreamParser({ jsonPaths: ['$.items'], onError: (err) => logger.error('stream parse failed', err) })","handlingStrategy":"type-guard","validationCode":"if (options.onError != null && typeof options.onError !== 'function') {\n  throw new TypeError('onError must be a function');\n}","typeGuard":"function isCallable(v) {\n  return typeof v === 'function';\n}","tryCatchPattern":"try {\n  return new StreamParser(options);\n} catch (err) {\n  if (err.message === 'onError must be a function') {\n    return new StreamParser({ ...options, onError: (e) => console.error(e) });\n  }\n  throw err;\n}","preventionTips":["Wrap loggers instead of passing logger objects: onError: (e) => logger.error(e).","Use function types in TS interfaces for callback options.","Fail fast in a shared factory that validates all callbacks before construction."],"tags":["configuration","validation","callbacks"],"backgroundTag":"wrong-argument-type","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}