{"record":{"id":"f169c2058c4e4319","repo":"denoland/deno","slug":"err-ambiguous-argument","errorCode":"ERR_AMBIGUOUS_ARGUMENT","errorMessage":"The \"error/message\" argument is ambiguous. The error message \"${actual.message}\" is identical to the message.","messagePattern":"The \"error/message\" argument is ambiguous\\. The error message \"(.+?)\" is identical to the message\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":394,"sourceCode":"\nfunction expectsError(\n  stackStartFn,\n  actual,\n  error,\n  message,\n) {\n  if (typeof error === \"string\") {\n    if (arguments.length === 4) {\n      throw new ERR_INVALID_ARG_TYPE(\"error\", [\n        \"Object\",\n        \"Error\",\n        \"Function\",\n        \"RegExp\",\n      ], error);\n    }\n    if (typeof actual === \"object\" && actual !== null) {\n      if (actual.message === error) {\n        throw new ERR_AMBIGUOUS_ARGUMENT(\n          \"error/message\",\n          `The error message \"${actual.message}\" is identical to the message.`,\n        );\n      }\n    } else if (actual === error) {\n      throw new ERR_AMBIGUOUS_ARGUMENT(\n        \"error/message\",\n        `The error \"${actual}\" is identical to the message.`,\n      );\n    }\n    message = error;\n    error = undefined;\n  } else if (\n    error != null &&\n    typeof error !== \"object\" &&\n    typeof error !== \"function\"\n  ) {\n    throw new ERR_INVALID_ARG_TYPE(\"error\", [","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/assert.ts#L376-L412","documentation":"When a string error spec is used with assert.throws/assert.rejects, expectsError compares it to the thrown error's message. If the two are identical, the call is ambiguous — the same text is both the expected message and (implicitly) the assertion's failure message — so the polyfill throws ERR_AMBIGUOUS_ARGUMENT instead of guessing. Older Node versions only warned (DEP0018-adjacent behavior); current Node and this polyfill throw.","triggerScenarios":"assert.throws(() => { throw new Error('boom') }, 'boom') — the thrown Error's .message is strictly equal to the string passed as the expectation.","commonSituations":"Tests written as assert.throws(fn, err.message) after capturing a message dynamically, making expected and actual text identical by construction; generated tests that build the expected string from the same constant the code under test throws; upgrading Node/Deno from versions that tolerated this with a deprecation warning, breaking previously green suites.","solutions":["Wrap the expectation in a RegExp: assert.throws(fn, /boom/).","Or use a validation object: assert.throws(fn, { message: 'boom' }).","If the string was meant as the assertion's failure message, move it to the third argument: assert.throws(fn, undefined, 'boom') — or simply assert.throws(fn) and let the thrown error speak for itself.","When building expectations dynamically, derive them from a different source than the runtime message (a shared constant is fine, but change one side's form, e.g. new RegExp(escaped))."],"exampleFix":"// before\nassert.throws(() => { throw new Error('boom'); }, 'boom');\n\n// after\nassert.throws(() => { throw new Error('boom'); }, /boom/);","handlingStrategy":"validation","validationCode":"// Compare by pattern, never by identical literal string\nconst expectMessage = (msg) => (msg instanceof RegExp ? msg : new RegExp(msg));\nassert.throws(fn, expectMessage(thrownMessage));","typeGuard":"const isUnambiguousErrorSpec = (error, actualMsg) =>\n  !(typeof error === 'string' && error === actualMsg);","tryCatchPattern":"try {\n  assert.throws(fn, 'boom');\n} catch (e) {\n  if (e.code === 'ERR_AMBIGUOUS_ARGUMENT') {\n    assert.throws(fn, /boom/); // re-express the expectation unambiguously\n  } else throw e;\n}","preventionTips":["Avoid string expectations entirely; prefer RegExp or { message } objects.","Never build the expected string from the same runtime value the code throws.","When upgrading runtimes, grep tests for assert.throws(fn, '<literal>') patterns that duplicate thrown messages."],"tags":["assert","assert-throws","ambiguous-argument","node-compat","deno"],"backgroundTag":"ambiguous-argument","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}