Function argument is ambiguous or cannot be used as specified
Production Risk
Low — caught in test code; fix argument types to express clear test intent.
Thrown when an argument passed to a Node.js API is ambiguous — typically in assert functions where the combination of arguments does not clearly express the developers intent. For example, calling assert.doesNotThrow() with a string first argument is ambiguous because strings are not functions.
- 1Passing a string as the first argument to assert.throws() or assert.doesNotThrow() instead of a function
- 2Using assert.doesNotReject() with a message as the first argument
- 3API arguments that could be interpreted in multiple ways
Triggered when an assert API receives an argument combination that is ambiguous.
const assert = require('assert');
// String passed as function — ambiguous
assert.doesNotThrow('should not throw', 'error message');expected output
TypeError [ERR_AMBIGUOUS_ARGUMENT]: The "fn" argument must be of type Function. Received type string ('should not throw')Fix
Pass a function as the first argument to assert.doesNotThrow()
WHEN When using assert.throws() or assert.doesNotThrow()
const assert = require('assert');
assert.doesNotThrow(() => {
const x = 1 + 1; // should not throw
}, 'arithmetic should not throw');Why this works
Providing a function as the first argument clearly expresses the intent to assert about the functions behaviour.
const assert = require('assert');
// String passed as function — ambiguous
assert.doesNotThrow('should not throw', 'error message'); // this triggers ERR_AMBIGUOUS_ARGUMENTtry {
// operation that may throw ERR_AMBIGUOUS_ARGUMENT
riskyOperation()
} catch (err) {
if (err.code === 'ERR_AMBIGUOUS_ARGUMENT') {
console.error('ERR_AMBIGUOUS_ARGUMENT:', err.message)
} else {
throw err
}
}// Validate inputs before calling the operation
function safe_err_ambiguous_argument(...args) {
// validate args here
return performOperation(...args)
}✕ Pass strings or other non-functions as the fn argument to assert.throws()
The ambiguity makes the test intent unclear and is now a hard error.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev