{"record":{"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/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/client/lib/commands/MSET.ts#L1-L30","documentation":"parseMSetArguments rejects an empty array argument for MSET. MSET requires at least one key-value pair; an empty array means there is nothing to set and the server would reject the command anyway with a wrong number of arguments error.","triggerScenarios":"Calling client.mSet([]) with an empty flat array, client.mSet([[]]) with an empty tuple array, or passing an empty Record object that Object.entries turns into zero pairs.","commonSituations":"Dynamically building the key-value map from a data source that returned no results; conditional logic that produces an empty collection; batching logic that occasionally produces zero entries.","solutions":["Guard the call with a length check: if (entries.length > 0) await client.mSet(entries)","Skip the MSET call entirely when the collection is empty","Use Object.keys(obj).length > 0 before calling mSet with a Record"],"exampleFix":"// before\nawait client.mSet(pairs);\n// after\nif (pairs.length > 0) {\n  await client.mSet(pairs);\n}","handlingStrategy":"validation","validationCode":"// Guard against empty collections before calling mSet.\nfunction hasEntries(data: Array<[string, string]> | Array<string> | Record<string, string>): boolean {\n  if (Array.isArray(data)) return data.length > 0;\n  return Object.keys(data).length > 0;\n}\n\nif (hasEntries(pairs)) {\n  await client.mSet(pairs);\n}","typeGuard":"function isNonEmptyArray<T>(arr: T[]): arr is [T, ...T[]] {\n  return arr.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always check array length or object key count before calling mSet","Skip the call entirely when there is nothing to set","Use a wrapper utility that short-circuits on empty input"],"tags":["command","validation","arguments","mset"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}