{"record":{"id":"f761b1aadf1a76f0","repo":"denoland/deno","slug":"err-invalid-arg-value-f761b1","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'error' may not be an empty object. Received ${expected}","messagePattern":"The argument 'error' may not be an empty object\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":246,"sourceCode":"      const err = new AssertionError({\n        actual,\n        expected,\n        message,\n        operator: \"deepStrictEqual\",\n        stackStartFn: fn,\n        diff: this?.[kOptions]?.diff,\n      });\n      err.operator = fn.name;\n      throw err;\n    } else {\n      // Handle validation objects.\n      const keys = ObjectKeys(expected);\n      // Special handle errors to make sure the name and the message are\n      // compared as well.\n      if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, expected)) {\n        ArrayPrototypePush(keys, \"name\", \"message\");\n      } else if (keys.length === 0) {\n        throw new ERR_INVALID_ARG_VALUE(\n          \"error\",\n          expected,\n          \"may not be an empty object\",\n        );\n      }\n      for (const key of new SafeArrayIterator(keys)) {\n        if (\n          typeof actual[key] === \"string\" &&\n          isRegExp(expected[key]) &&\n          RegExpPrototypeExec(expected[key], actual[key]) !== null\n        ) {\n          continue;\n        }\n        compareExceptionKey(actual, expected, key, message, keys, fn);\n      }\n      return;\n    }\n    // Guard instanceof against arrow functions as they don't have a prototype.","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/assert.ts#L228-L264","documentation":"In assert.throws/assert.rejects, when the expected argument is a plain object it acts as a property validator: its own keys are checked against the thrown error, so an object with zero keys validates nothing and is rejected up front (ext/node/polyfills/assert.ts:246) with ERR_INVALID_ARG_VALUE 'error may not be an empty object'. Note that Error instances are exempt (name/message are implicitly added), but {}, Object.create(null), or objects whose own enumerable keys are absent throw.","triggerScenarios":"assert.throws(fn, {}); assert.rejects(promise, {}); dynamic expected objects built from optional fields where every field was undefined or non-enumerable, leaving zero keys.","commonSituations":"Placeholder tests written as assert.throws(fn, {}) meaning 'any throw'; config-driven assertion builders merging optional matchers that end up empty; objects whose properties are defined only on the prototype (ObjectKeys sees none).","solutions":["Drop the second argument entirely to assert 'throws with anything': assert.throws(fn)","Specify at least one property to validate: assert.throws(fn, { name: 'TypeError' })","When building expected dynamically, fall back to a bare call when the matcher object would be empty: Object.keys(matcher).length ? assert.throws(fn, matcher) : assert.throws(fn)"],"exampleFix":"// before\nassert.throws(() => JSON.parse('{'), {});\n\n// after\nassert.throws(() => JSON.parse('{'), { name: 'SyntaxError' });","handlingStrategy":"validation","validationCode":"if (matcher && typeof matcher === 'object' && !Object.keys(matcher).length) matcher = undefined; // assert 'throws with anything'","typeGuard":"function isNonEmptyErrorMatcher(v) { return v == null || typeof v === 'function' || Object.keys(v).length > 0 || v instanceof Error; }","tryCatchPattern":"try { assert.throws(fn, matcher); } catch (e) { if (e.code === 'ERR_INVALID_ARG_VALUE' && /empty object/.test(e.message)) assert.throws(fn); else throw e; }","preventionTips":["Never use {} as the expected argument; omit it to assert any throw","When building matchers dynamically, assert at least one key before use"],"tags":["assert","testing","validation","throws","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}