{"record":{"id":"2630c2268bc41a0c","repo":"avajs/ava","slug":"the-message-property-of-the-second-argument-to","errorCode":null,"errorMessage":"The `message` property of the second argument to `${assertion}` must be a string, regular expression or a function","messagePattern":"The `message` property of the second argument to `(.+?)` must be a string, regular expression or a function","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":111,"sourceCode":"\t\tthrow new AssertionError(`The second argument to \\`${assertion}\\` must be an expectation object, \\`null\\` or \\`undefined\\``, {\n\t\t\tassertion,\n\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t});\n\t} else {\n\t\tif (Object.hasOwn(expectations, 'instanceOf') && typeof expectations.instanceOf !== 'function') {\n\t\t\tthrow new AssertionError(`The \\`instanceOf\\` property of the second argument to \\`${assertion}\\` must be 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 (\n\t\t\tObject.hasOwn(expectations, 'message')\n\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}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L93-L129","documentation":"validateExpectations guard: expectations.message must be a string, RegExp, or function used to match the thrown error's message, but some other type (number, object, boolean, etc.) was given. The input at fault is expectations.message.","triggerScenarios":"Thrown at lib/assert.js:111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a string for exact comparison or a RegExp for partial matching","Use a function (message) => boolean for custom matching","Coerce numbers/objects to strings before placing them in message"],"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"}