{"id":"4a2cf30661bbeae8","repo":"redis/node-redis","slug":"empty-toset-argument","errorCode":null,"errorMessage":"empty toSet Argument","messagePattern":"empty toSet Argument","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/client/lib/commands/MSET.ts","lineNumber":12,"sourceCode":"import { CommandParser } from '../client/parser';\nimport { RedisArgument, SimpleStringReply, Command } from '../RESP/types';\n\nexport type MSetArguments =\n  Array<[RedisArgument, RedisArgument]> |\n  Array<RedisArgument> |\n  Record<string, RedisArgument>;\n\nexport function parseMSetArguments(parser: CommandParser, toSet: MSetArguments) {\n  if (Array.isArray(toSet)) {\n    if (toSet.length == 0) {\n      throw new Error(\"empty toSet Argument\")\n    }\n    if (Array.isArray(toSet[0])) {\n      for (const tuple of (toSet as Array<[RedisArgument, RedisArgument]>)) {\n        parser.pushKey(tuple[0]);\n        parser.push(tuple[1]);\n      }\n    } else {\n      const arr = toSet as Array<RedisArgument>;\n      for (let i=0; i < arr.length; i += 2) {\n        parser.pushKey(arr[i]);\n        parser.push(arr[i+1]);\n      }\n    }\n  } else {\n    for (const tuple of Object.entries(toSet)) {\n      parser.pushKey(tuple[0]);\n      parser.push(tuple[1]);\n    }","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/commands/MSET.ts#L1-L30","documentation":"Thrown by parseMSetArguments when the toSet argument passed to MSET is an Array with length 0. MSET requires at least one key/value pair; an empty array has nothing to send and the client rejects it before issuing the command.","triggerScenarios":"Calling client.mset([]) or client.mSet([]). Also reachable when a dynamically-built array of key/value tuples is empty because upstream filtering removed all entries.","commonSituations":"Batch-building an MSET payload from a source that can be empty (e.g. flushing buffered writes when the buffer happens to be empty); refactoring that leaves a placeholder empty array.","solutions":["Guard the call: skip MSET entirely when the array is empty.","Ensure at least one key/value pair is present before calling.","If building from entries, filter to pairs and assert non-empty."],"exampleFix":"// before\nawait client.mSet(entries); // entries may be []\n\n// after\nif (entries.length > 0) await client.mSet(entries);","handlingStrategy":"validation","validationCode":"function nonEmptyKv(a) { if (Array.isArray(a) && a.length === 0) throw new Error('mSet needs >=1 pair'); }\nnonEmptyKv(toSet); await client.mSet(toSet);","typeGuard":"function hasMSetPairs(a) { return Array.isArray(a) ? a.length > 0 : a != null && Object.keys(a).length > 0; }","tryCatchPattern":"if (hasMSetPairs(toSet)) await client.mSet(toSet);","preventionTips":["Skip MSET when the change set is empty.","Build the pairs array from a guaranteed non-empty source or guard with length check.","Centralize batch-write helpers with an empty guard."],"tags":["mset","validation","user-error","arguments"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}