{"record":{"id":"4c16a397e12806c9","repo":"mochajs/mocha","slug":"invalid-argument-expected-a-non-empty-object","errorCode":null,"errorMessage":"Invalid argument; expected a non-empty object","messagePattern":"Invalid argument; expected a non-empty object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/utils.cjs","lineNumber":605,"sourceCode":"    [Object.create(null)].concat(Array.prototype.slice.call(arguments)),\n  );\n};\n\n/**\n * Creates a read-only map-like object.\n *\n * @description\n * This differs from {@link module:utils.createMap createMap} only in that\n * the argument must be non-empty, because the result is frozen.\n *\n * @see {@link module:utils.createMap createMap}\n * @param {...*} [obj] - Arguments to `Object.assign()`.\n * @returns {Object} A frozen object with no prototype, having `...obj` properties\n * @throws {TypeError} if argument is not a non-empty object.\n */\nexports.defineConstants = function (obj) {\n  if (canonicalType(obj) !== \"object\" || !Object.keys(obj).length) {\n    throw new TypeError(\"Invalid argument; expected a non-empty object\");\n  }\n  return Object.freeze(exports.createMap(obj));\n};\n\n/**\n * Returns current working directory\n *\n * Wrapper around `process.cwd()` for isolation\n * @private\n */\nexports.cwd = function cwd() {\n  return process.cwd();\n};\n\n/**\n * Returns `true` if Mocha is running in a browser.\n * Checks for `process.browser`.\n * @returns {boolean}","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/utils.cjs#L587-L623","documentation":"`utils.defineConstants(obj)` creates a frozen, prototype-less map of constants, and it only accepts a non-empty plain object. If the argument is not an object (or is an object with no own keys), it throws this TypeError as an early contract violation so callers do not silently create an empty constants map.","triggerScenarios":"Calling `utils.defineConstants()` with undefined/null, with a non-object (string, array misuse), or with `{}`/`new Object()` containing no keys.","commonSituations":"Internal refactors where a constants object is built dynamically and ends up empty (e.g. filtering removed every key); plugin authors reaching into mocha's internal utils and passing the wrong shape; typos where a variable that should hold the object is still undefined.","solutions":["Pass a non-empty plain object literal to defineConstants","Log/inspect the argument with canonicalType and Object.keys before the call to see why it is empty or not an object","Fix upstream code that builds the object so at least one key exists","If constants are legitimately empty, skip the call instead of calling with {}"],"exampleFix":"// before\nutils.defineConstants({});\n// after\nutils.defineConstants({ MOCHA_VERSION: '1.0.0' });","handlingStrategy":"validation","validationCode":"function isNonEmptyObject(v) {\n  return canonicalType(v) === 'object' && Object.keys(v).length > 0;\n}\nif (!isNonEmptyObject(myConstants)) throw new TypeError('defineConstants needs a non-empty object');\nutils.defineConstants(myConstants);","typeGuard":"const isNonEmptyPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0;","tryCatchPattern":"try {\n  utils.defineConstants(obj);\n} catch (err) {\n  if (!(err instanceof TypeError)) throw err;\n  console.error('defineConstants requires a non-empty object, got:', obj);\n}","preventionTips":["Validate object shape and key count before calling internal utils","Assert dynamically built constants objects are non-empty before use","Prefer mocha's public API over internal utils"],"tags":["validation","typeerror","internal-api"],"backgroundTag":"invalid-argument-value","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}