{"record":{"id":"756eb741d1cb179c","repo":"remix-run/remix","slug":"err-invalid-arg-type","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"error\" argument must be of type function or an instance of Error, RegExp, or Object. Received ${formatReceived(expectedError)}","messagePattern":"The \"error\" argument must be of type function or an instance of Error, RegExp, or Object\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/assert/src/lib/assert.ts","lineNumber":173,"sourceCode":"  if (typeof expectedErrorOrMessage === 'string') {\n    return { expectedError: undefined, message: expectedErrorOrMessage }\n  }\n\n  return { expectedError: expectedErrorOrMessage, message }\n}\n\nfunction validateExpectedError(expectedError: unknown): void {\n  if (\n    expectedError == null ||\n    typeof expectedError === 'function' ||\n    expectedError instanceof Error ||\n    expectedError instanceof RegExp ||\n    typeof expectedError === 'object'\n  ) {\n    return\n  }\n\n  throw createInvalidArgumentTypeError(\n    'error',\n    'of type function or an instance of Error, RegExp, or Object',\n    expectedError,\n  )\n}\n\nfunction validateExpectedDoesNotError(expectedError: unknown): void {\n  if (\n    expectedError == null ||\n    typeof expectedError === 'function' ||\n    expectedError instanceof RegExp\n  ) {\n    return\n  }\n\n  throw createInvalidArgumentTypeError(\n    'expected',\n    'of type function or an instance of RegExp',","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/assert/src/lib/assert.ts#L155-L191","documentation":"assert.throws()/rejects() validates its `error` expectation argument before running. It must be a function (error class), an Error instance, a RegExp (matched against message), or a plain object (partial property match); anything else throws ERR_INVALID_ARG_TYPE.","triggerScenarios":"Passing a string, number, or other primitive as the expected-error argument, e.g. assert.throws(fn, 'expected message') (strings are not accepted, unlike some other frameworks).","commonSituations":"Porting tests from Jest/Chai where a string expectation is allowed, or passing an error code string instead of an object like { code: 'ENOENT' }.","solutions":["Wrap string expectations in a RegExp: /expected message/","Use an object for property matching: { code: 'ERR_X' } or { name: 'TypeError' }","Use an error class function for constructor checks"],"exampleFix":"// before\nassert.throws(() => parse('x'), 'invalid input')\n// after\nassert.throws(() => parse('x'), /invalid input/)","handlingStrategy":"type-guard","validationCode":"const isValidExpectation = (e) =>\n  typeof e === 'function' || e instanceof Error || e instanceof RegExp ||\n  (typeof e === 'object' && e !== null && Object.keys(e).length > 0)","typeGuard":"function isErrorExpectation(value: unknown): value is Function | Error | RegExp | object {\n  return (\n    typeof value === 'function' ||\n    value instanceof Error ||\n    value instanceof RegExp ||\n    (typeof value === 'object' && value !== null)\n  )\n}","tryCatchPattern":null,"preventionTips":["Use RegExp for message matching, objects for property matching, classes for type matching","Never pass a plain string expectation to assert.throws"],"tags":["assert","invalid-arg","validation"],"backgroundTag":"assert-invalid-argument-type","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}