{"record":{"id":"9ea5ed629795d31b","repo":"caolan/async","slug":"invalid-arguments-for-async-retry","errorCode":null,"errorMessage":"Invalid arguments for async.retry","messagePattern":"Invalid arguments for async\\.retry","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/retry.js","lineNumber":113,"sourceCode":"const DEFAULT_TIMES = 5;\nconst DEFAULT_INTERVAL = 0;\n\nexport default function retry(opts, task, callback) {\n    var options = {\n        times: DEFAULT_TIMES,\n        intervalFunc: constant(DEFAULT_INTERVAL)\n    };\n\n    if (arguments.length < 3 && typeof opts === 'function') {\n        callback = task || promiseCallback();\n        task = opts;\n    } else {\n        parseTimes(options, opts);\n        callback = callback || promiseCallback();\n    }\n\n    if (typeof task !== 'function') {\n        throw new Error(\"Invalid arguments for async.retry\");\n    }\n\n    var _task = wrapAsync(task);\n\n    var attempt = 1;\n    function retryAttempt() {\n        _task((err, ...args) => {\n            if (err === false) return\n            if (err && attempt++ < options.times &&\n                (typeof options.errorFilter != 'function' ||\n                    options.errorFilter(err))) {\n                setTimeout(retryAttempt, options.intervalFunc(attempt - 1));\n            } else {\n                callback(err, ...args);\n            }\n        });\n    }\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/caolan/async/blob/13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a/lib/retry.js#L95-L131","documentation":"async.retry() throws 'Invalid arguments for async.retry' when the task argument passed as the last positional argument is not a function. The library expects retry(task, [opts], [callback]) where task is the function to re-attempt; anything else (undefined, an object, a string) cannot be wrapped by wrapAsync and is rejected eagerly. This is an argument-validation error designed to fail fast instead of crashing later inside the retry loop.","triggerScenarios":"Calling async.retry with a non-function as the task argument: async.retry(5, opts) where the function was forgotten, async.retry(options) with only an options object and no task, passing a variable that is undefined because the task function is misnamed or not yet imported, or passing a promise instead of a callback-style function.","commonSituations":"Refactoring that renamed the task function leaving a stale reference (undefined at call time); passing an async/await-style function wrapper object instead of a function; copy-pasted calls like async.retry({times: 3}, config) missing the actual worker; TypeScript/JS interop where an optional task defaults to undefined.","solutions":["Ensure the last argument passed to async.retry is the task function to run","Check the task variable is defined and typeof === 'function' before calling retry","Correct the argument order: retry(timesOrOpts, task, callback) — do not omit the task","If using promises, pass an async function, not a Promise instance"],"exampleFix":"// before\nasync.retry({times: 3}, taskConfig); // taskConfig is not a function\n// after\nasync.retry({times: 3}, fetchWithBackoff, function(err, result) { ... });","handlingStrategy":"type-guard","validationCode":"if (typeof task !== 'function') { throw new TypeError('retry: task must be a function, got ' + typeof task); }","typeGuard":"function isTask(v) { return typeof v === 'function'; }","tryCatchPattern":"try {\n  async.retry(opts, task, cb);\n} catch (err) {\n  if (err.message.includes('Invalid arguments for async.retry')) {\n    console.error('retry task argument must be a function, got:', typeof task);\n  } else { throw err; }\n}","preventionTips":["Always pass the task function as the last positional argument before the callback","Assert typeof task === 'function' at module boundaries","Use TypeScript signatures so missing/non-function tasks are caught at compile time","Avoid passing Promises; wrap await-style code in an async function"],"tags":["argument-validation","async","retry","type-error"],"backgroundTag":"invalid-function-argument","analyzedSha":"13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a","analyzedAt":"2026-08-28T22:50:46.507Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}