caolan/async · error · Error

could not parse args in autoInject Source: ${src}

Error message

could not parse args in autoInject
Source:
${src}

What it means

autoInject parses the source text of each task function (via Function.prototype.toString) to infer its dependency names from parameter names. If regex matching for standard or arrow function signatures fails, parseParams throws with the stripped source included to aid debugging. Minified or exotic function forms defeat the parser.

Source

Thrown at lib/autoInject.js:43

            } else {
                stripped += string[index];
                index++;
            }
        } else {
            stripped += string[index];
            index++;
        }
    }
    return stripped;
}

function parseParams(func) {
    const src = stripComments(func.toString());
    let match = src.match(FN_ARGS);
    if (!match) {
        match = src.match(ARROW_FN_ARGS);
    }
    if (!match) throw new Error('could not parse args in autoInject\nSource:\n' + src)
    let [, args] = match
    return args
        .replace(/\s/g, '')
        .split(FN_ARG_SPLIT)
        .map((arg) => arg.replace(FN_ARG, '').trim());
}

/**
 * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
 * tasks are specified as parameters to the function, after the usual callback
 * parameter, with the parameter names matching the names of the tasks it
 * depends on. This can provide even more readable task graphs which can be
 * easier to maintain.
 *
 * If a final callback is specified, the task results are similarly injected,
 * specified as named parameters after the initial error parameter.
 *
 * The autoInject function is purely syntactic sugar and its semantics are

View on GitHub (pinned to 13dfaf13f3)

Solutions

  1. Use plain function expressions or arrow functions with explicit parameter lists
  2. Disable minification for the module containing autoInject tasks or use reserved/kept param names
  3. Fall back to plain async.auto with explicit dependency arrays
  4. Upgrade async to a version with broader parser coverage

Example fix

// before (minified)
autoInject({task: (e,r)=>r(null,e*2)});
// after
autoInject({
  task: (env, cb) => cb(null, env * 2)
});
Defensive patterns

Strategy: validation

Validate before calling

function assertParsable(fn) {
  const src = fn.toString();
  const ok = /function\s*\(([^)]*)\)/.test(src) || /\(([^)]*)\)\s*=>/.test(src);
  if (!ok) throw new Error('autoInject cannot parse: ' + src);
}

Try / catch

try {
  await autoInject(tasks);
} catch (err) {
  if (String(err.message).startsWith('could not parse args')) {
    console.error('Rewrite task as a plain function with named params');
  } else throw err;
}

Prevention

When it happens

Trigger: Passing functions autoInject cannot textual-parse: bound functions, native/built-in functions, some transpiled or minified arrow forms, or class methods where toString output does not match FN_ARGS/ARROW_FN_ARGS patterns.

Common situations: Bundled/minified production code renaming parameters (deps become single letters and parsing may fail on unusual syntax), TypeScript compile targets with exotic signatures, using .bind() which loses the original textual form expectations.

Related errors


AI-assisted analysis of caolan/async@13dfaf13f3 (2026-08-28). Data as JSON: /api/errors/183c2e257b3a1455. Report an issue: GitHub.