{"record":{"id":"c7c192fb48f46f0f","repo":"Automattic/mongoose","slug":"limit-must-be-positive","errorCode":null,"errorMessage":"Limit must be positive","messagePattern":"Limit must be positive","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/helpers/parallelLimit.js","lineNumber":13,"sourceCode":"'use strict';\n\nmodule.exports = parallelLimit;\n\n/*!\n * Run `fn` over every entry of `params` with at most `limit` calls in flight at\n * a time, resolving to the results in input order. Currently only used by\n * `Model.insertMany()` to bound how many documents validate concurrently.\n */\n\nasync function parallelLimit(params, fn, limit) {\n  if (limit <= 0) {\n    throw new Error('Limit must be positive');\n  }\n\n  const length = params.length;\n  if (length === 0) {\n    return [];\n  }\n\n  const results = new Array(length);\n  // Fast path: there's nothing to bound, so kick everything off and wait once.\n  // Avoids the per-task `Set` + `Promise.race` bookkeeping of a sliding window.\n  if (limit >= length) {\n    for (let i = 0; i < length; ++i) {\n      results[i] = fn(params[i], i);\n    }\n    return Promise.all(results);\n  }\n\n  let nextIndex = 0;","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/helpers/parallelLimit.js#L1-L31","documentation":"Error \"Limit must be positive\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/helpers/parallelLimit.js:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}