{"record":{"id":"21060ec13b4d7a1a","repo":"caolan/async","slug":"autoinject-task-functions-require-explicit-paramet","errorCode":null,"errorMessage":"autoInject task functions require explicit parameters.","messagePattern":"autoInject task functions require explicit parameters\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/autoInject.js","lineNumber":156,"sourceCode":"        var taskFn = tasks[key]\n        var params;\n        var fnIsAsync = isAsync(taskFn);\n        var hasNoDeps =\n            (!fnIsAsync && taskFn.length === 1) ||\n            (fnIsAsync && taskFn.length === 0);\n\n        if (Array.isArray(taskFn)) {\n            params = [...taskFn];\n            taskFn = params.pop();\n\n            newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);\n        } else if (hasNoDeps) {\n            // no dependencies, use the function as-is\n            newTasks[key] = taskFn;\n        } else {\n            params = parseParams(taskFn);\n            if ((taskFn.length === 0 && !fnIsAsync) && params.length === 0) {\n                throw new Error(\"autoInject task functions require explicit parameters.\");\n            }\n\n            // remove callback param\n            if (!fnIsAsync) params.pop();\n\n            newTasks[key] = params.concat(newTask);\n        }\n\n        function newTask(results, taskCb) {\n            var newArgs = params.map(name => results[name])\n            newArgs.push(taskCb);\n            wrapAsync(taskFn)(...newArgs);\n        }\n    });\n\n    return auto(newTasks, callback);\n}\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/caolan/async/blob/13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a/lib/autoInject.js#L138-L174","documentation":"autoInject infers dependencies from parameter names; a task function with zero parameters gives it nothing to infer. When the function has length 0, is not detected as an async-style function, and parsing also yields no params, autoInject throws because the task would be unusable. This catches forgetting to declare dependencies/callback entirely.","triggerScenarios":"autoInject({task: () => {...}}) or autoInject({task: function() {...}}) — a task declared with an empty parameter list that also doesn't match known async signatures (e.g. not an async function or returning a promise).","commonSituations":"Converting code from async.auto to autoInject and dropping the callback parameter, writing a no-arg task that actually needs the completion callback, TypeScript arrow functions compiled to parameterless forms.","solutions":["Add explicit parameters (the callback at minimum): (callback) => ...","Declare dependencies as named parameters, e.g. (data, callback) => ...","Use an async function or arrow returning a promise so fnIsAsync is true","Use async.auto with explicit dependency arrays instead"],"exampleFix":"// before\nautoInject({ task: () => doWork() });\n// after\nautoInject({ task: async () => { return doWork(); } });\n// or\nautoInject({ task: (callback) => doWork(callback) });","handlingStrategy":"validation","validationCode":"function assertAutoInjectTask(fn) {\n  if (fn.length === 0 && !/^\\s*async\\s/.test(fn.toString()) &&\n      !(fn instanceof (async function(){}).constructor)) {\n    throw new Error('autoInject task must declare params (deps and/or callback)');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await autoInject(tasks);\n} catch (err) {\n  if (String(err.message).includes('require explicit parameters')) {\n    console.error('Add a callback or make the task async');\n  } else throw err;\n}","preventionTips":["Always give task functions at least a (callback) parameter or declare them async","Review migrations from async.auto to autoInject for dropped params","Use async functions for dep-free tasks"],"tags":["async","autoinject","validation"],"backgroundTag":"missing-callback-parameter","analyzedSha":"13dfaf13f3fc809ba1c9c39d5e267ac6959cbf4a","analyzedAt":"2026-08-28T22:50:46.507Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}