denoland/deno · error · TypeError
ERR_AMBIGUOUS_ARGUMENT
ERR_AMBIGUOUS_ARGUMENT
Error message
The "error/message" argument is ambiguous. The error message "${actual.message}" is identical to the message. What it means
Thrown when a string matcher is identical to the message of the caught error. A string matcher never matches anything (it only labels the failure message), so an identical value means the author almost certainly intended message matching; assert refuses with ERR_AMBIGUOUS_ARGUMENT to prevent a test that would silently assert nothing.
Source
Thrown at ext/node/polyfills/assert.ts:394
function expectsError(
stackStartFn,
actual,
error,
message,
) {
if (typeof error === "string") {
if (arguments.length === 4) {
throw new ERR_INVALID_ARG_TYPE("error", [
"Object",
"Error",
"Function",
"RegExp",
], error);
}
if (typeof actual === "object" && actual !== null) {
if (actual.message === error) {
throw new ERR_AMBIGUOUS_ARGUMENT(
"error/message",
`The error message "${actual.message}" is identical to the message.`,
);
}
} else if (actual === error) {
throw new ERR_AMBIGUOUS_ARGUMENT(
"error/message",
`The error "${actual}" is identical to the message.`,
);
}
message = error;
error = undefined;
} else if (
error != null &&
typeof error !== "object" &&
typeof error !== "function"
) {
throw new ERR_INVALID_ARG_TYPE("error", [View on GitHub (pinned to 89f33cbef2)
Solutions
- Use a RegExp matcher: assert.throws(fn, /^boom$/)
- Use a constructor plus validation object: assert.throws(fn, { message: /^boom$/ })
- Keep the string only if you truly want a failure label, and make its text differ from the error message
Example fix
// before assert.throws(fn, 'boom'); // after assert.throws(fn, /^boom$/);
Defensive patterns
Strategy: validation
Validate before calling
if (typeof matcher === 'string') matcher = new RegExp(`^${escapeRegExp(matcher)}$`);
assert.throws(fn, matcher); Prevention
- Use RegExp for message matching; strings only label failures
- Escape dynamic strings before embedding them in RegExp
When it happens
Trigger: The function throws new Error('boom') and the test calls assert.throws(fn, 'boom'); the same via assert.rejects(fn, 'boom') when the rejection has message 'boom'.
Common situations: Porting tests from frameworks where a string matcher performs matching; pasting the exact expected message text into the matcher slot.
Related errors
- ERR_CONSTRUCT_CALL_REQUIRED
- ERR_ASSERTION
- ERR_INVALID_ARG_VALUE
- ERR_INVALID_RETURN_VALUE
- ERR_INVALID_ARG_TYPE
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/f169c2058c4e4319.
Report an issue: GitHub.