ERR_AMBIGUOUS_ARGUMENT
Node.jsERRORNotableValidationHIGH confidence

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.

What this means

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.

Why it happens
  1. 1Passing a string as the first argument to assert.throws() or assert.doesNotThrow() instead of a function
  2. 2Using assert.doesNotReject() with a message as the first argument
  3. 3API arguments that could be interpreted in multiple ways
How to reproduce

Triggered when an assert API receives an argument combination that is ambiguous.

trigger — this will error
trigger — this will error
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()

Pass a function as the first argument to 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.

Code examples
Triggerjs
const assert = require('assert');
// String passed as function — ambiguous
assert.doesNotThrow('should not throw', 'error message');  // this triggers ERR_AMBIGUOUS_ARGUMENT
Handle in try/catchjs
try {
  // 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
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_ambiguous_argument(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

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.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors