{"record":{"id":"cd09434964e7dfd3","repo":"FlowiseAI/Flowise","slug":"limit-cannot-be-less-than-0","errorCode":null,"errorMessage":"Limit cannot be less than 0","messagePattern":"Limit cannot be less than 0","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/components/nodes/documentloaders/Cheerio/Cheerio.ts","lineNumber":190,"sourceCode":"                } else {\n                    docs = await loader.load()\n                }\n                return docs\n            } catch (err) {\n                if (process.env.DEBUG === 'true')\n                    options.logger.error(`[${orgId}]: Error in CheerioWebBaseLoader: ${err.message}, on page: ${url}`)\n                return []\n            }\n        }\n\n        let docs: IDocument[] = []\n\n        if (relativeLinksMethod) {\n            if (process.env.DEBUG === 'true') options.logger.info(`[${orgId}]: Start CheerioWebBaseLoader ${relativeLinksMethod}`)\n            // if limit is 0 we don't want it to default to 10 so we check explicitly for null or undefined\n            // so when limit is 0 we can fetch all the links\n            if (limit === null || limit === undefined) limit = 10\n            else if (limit < 0) throw new Error('Limit cannot be less than 0')\n            const pages: string[] =\n                selectedLinks && selectedLinks.length > 0\n                    ? selectedLinks.slice(0, limit === 0 ? undefined : limit)\n                    : relativeLinksMethod === 'webCrawl'\n                    ? await webCrawl(url, limit)\n                    : await xmlScrape(url, limit)\n            if (process.env.DEBUG === 'true')\n                options.logger.info(`[${orgId}]: CheerioWebBaseLoader pages: ${JSON.stringify(pages)}, length: ${pages.length}`)\n            if (!pages || pages.length === 0) throw new Error('No relative links found')\n            for (const page of pages) {\n                docs.push(...(await cheerioLoader(page)))\n            }\n            if (process.env.DEBUG === 'true') options.logger.info(`[${orgId}]: Finish CheerioWebBaseLoader ${relativeLinksMethod}`)\n        } else if (selectedLinks && selectedLinks.length > 0) {\n            if (process.env.DEBUG === 'true')\n                options.logger.info(\n                    `[${orgId}]: CheerioWebBaseLoader pages: ${JSON.stringify(selectedLinks)}, length: ${selectedLinks.length}`\n                )","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/Cheerio/Cheerio.ts#L172-L208","documentation":"When relativeLinksMethod (webCrawl or xmlScrape) is set, the loader enforces a non-negative limit. limit = parseInt(nodeData.inputs?.limit). Note: a non-numeric string yields NaN, and NaN < 0 is false, so this guard only catches actual negative numbers; NaN falls through and silently becomes 'fetch all' when limit===0 logic does not apply, or slices weirdly downstream.","triggerScenarios":"User explicitly typed a negative number in the 'limit' field; a templated value resolved to e.g. '-1'; limit was decremented arithmetically upstream and went below zero.","commonSituations":"Confusion about '0 means fetch all' leading users to try '-1'; arithmetic on limit from a previous node producing a negative value.","solutions":["Set limit to 0 (fetch all) or a positive integer; remove the negative value.","If limit comes from a variable, clamp it upstream: limit = Math.max(0, Number(limit) || 10).","Add a guard for NaN before this point so non-numeric input does not silently misbehave."],"exampleFix":"// before\nlet limit = parseInt(nodeData.inputs?.limit as string)\n// ...\nelse if (limit < 0) throw new Error('Limit cannot be less than 0')\n// after - handle NaN explicitly and clamp\nlet limit = parseInt(nodeData.inputs?.limit as string, 10)\nif (Number.isNaN(limit)) limit = 10\nif (limit < 0) throw new Error(`Limit cannot be less than 0 (got ${limit})`)","handlingStrategy":"validation","validationCode":"function resolveLimit(raw: unknown): number {\n  if (raw === null || raw === undefined || raw === '') return 10\n  const n = typeof raw === 'number' ? raw : parseInt(String(raw), 10)\n  if (!Number.isFinite(n)) throw new Error(`limit must be a number, got ${JSON.stringify(raw)}`)\n  if (n < 0) throw new Error(`limit cannot be negative, got ${n}`)\n  return n\n}\n// const limit = resolveLimit(nodeData.inputs?.limit)","typeGuard":"function isNonNegativeInteger(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0\n}","tryCatchPattern":null,"preventionTips":["Use 0 explicitly when you want all links; do not use -1.","Clamp upstream: Math.max(0, Number(limit) || 10).","Guard NaN explicitly because parseInt('abc') silently returns NaN."],"tags":["validation","configuration","cheerio","web-crawl"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}