{"record":{"id":"304f1b598970defd","repo":"avajs/ava","slug":"the-code-property-of-the-second-argument-to-a","errorCode":null,"errorMessage":"The `code` property of the second argument to `${assertion}` must be a string or number","messagePattern":"The `code` property of the second argument to `(.+?)` must be a string or number","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":125,"sourceCode":"\t\t\t&& typeof expectations.message !== 'string'\n\t\t\t&& !(expectations.message instanceof RegExp)\n\t\t\t&& !(typeof expectations.message === 'function')\n\t\t) {\n\t\t\tthrow new AssertionError(`The \\`message\\` property of the second argument to \\`${assertion}\\` must be a string, regular expression or a function`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'name') && typeof expectations.name !== 'string') {\n\t\t\tthrow new AssertionError(`The \\`name\\` property of the second argument to \\`${assertion}\\` must be a string`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'code') && typeof expectations.code !== 'string' && typeof expectations.code !== 'number') {\n\t\t\tthrow new AssertionError(`The \\`code\\` property of the second argument to \\`${assertion}\\` must be a string or number`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'any') && typeof expectations.any !== 'boolean') {\n\t\t\tthrow new AssertionError(`The \\`any\\` property of the second argument to \\`${assertion}\\` must be a boolean`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tfor (const key of Object.keys(expectations)) {\n\t\t\tswitch (key) {\n\t\t\t\tcase 'instanceOf':\n\t\t\t\tcase 'is':\n\t\t\t\tcase 'message':\n\t\t\t\tcase 'name':","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L107-L143","documentation":"This is an input-validation failure inside validateExpectations, the guard that checks the expectations object supplied as the second argument to assertion helpers like t.throws() or t.notThrows(). It fires when expectations has a `code` key whose value is neither a string nor a number (e.g. a boolean, object, or symbol), leaving the assertion unable to compare it against an error's code. The assertion is rejected before execution — it is an API misuse rather than a test failure. Fix by passing expectations.code as a string or number.","triggerScenarios":"Thrown at lib/assert.js:125 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the code as a string ('ERR_ASSERTION') or number (errno-style)","Do not wrap the code in an object or array","Remove the code key if the error carries no code property"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}