{"record":{"id":"90f0cd7929cd1d4d","repo":"microsoft/garnet","slug":"elements-collection-cannot-be-empty","errorCode":null,"errorMessage":"Elements collection cannot be empty.","messagePattern":"Elements collection cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"libs/client/GarnetClientAPI/GarnetClientListCommands.cs","lineNumber":47,"sourceCode":"\n        /// <summary>\n        /// Add the specified elements to the head of the list stored at key.\n        /// </summary>\n        /// <param name=\"key\">The key of the list.</param>\n        /// <param name=\"elements\">The elements to be added.</param>\n        /// <param name=\"callback\">The callback function when operation completes.</param>\n        /// <param name=\"context\">An optional context to correlate request to callback.</param>\n        public void ListLeftPush(string key, IEnumerable<string> elements, Action<long, long, string> callback, long context = 0)\n        {\n            ArgumentNullException.ThrowIfNull(key);\n            ArgumentNullException.ThrowIfNull(elements);\n            ArgumentNullException.ThrowIfNull(callback);\n\n            var arrElem = new[] { key }.Union(elements).ToArray();\n\n            if (arrElem.Length == 1)\n            {\n                throw new ArgumentException(\"Elements collection cannot be empty.\", nameof(elements));\n            }\n\n            ExecuteForLongResult(callback, context, nameof(LPUSH), arrElem);\n        }\n\n        /// <summary>\n        /// Asynchronously add the specified elements to the head of the list stored at key.\n        /// </summary>\n        /// <param name=\"key\">The key of the list.</param>\n        /// <param name=\"elements\">The elements to be added.</param>\n        /// <returns>The number of list elements after the addition.</returns>\n        public async Task<long> ListLeftPushAsync(string key, params string[] elements)\n        {\n            ArgumentNullException.ThrowIfNull(key);\n            ArgumentNullException.ThrowIfNull(elements);\n\n            if (elements.Length == 0)\n            {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/client/GarnetClientAPI/GarnetClientListCommands.cs#L29-L65","documentation":"ListLeftPush(key, IEnumerable<string> elements, ...) builds arrElem = {key} ∪ elements and throws ArgumentException when the union has length 1 — meaning elements contributed zero items. This rejects an empty LPUSH (Redis semantics: LPUSH requires at least one value). The key-only array is detected as the degenerate case.","triggerScenarios":"Calling ListLeftPush with an empty IEnumerable<string>, or one whose Union with {key} yields only the key (e.g. elements is an empty list, or contains only items already equal to key that get de-duplicated by Union).","commonSituations":"Passing an empty collection variable (e.g. from a query that returned no rows); a default/empty List<string>; a code path that pushes only when data exists but the guard is missing.","solutions":["Check elements.Any() before calling ListLeftPush, or skip the call entirely when there is nothing to push.","Use the async ListLeftPushAsync(params string[]) overload only if you have at least one element.","Guard the caller to never construct an empty push."],"exampleFix":"// before\nclient.ListLeftPush(key, values, callback);\n\n// after — skip empty pushes\nif (values is null || !values.Any()) return;\nclient.ListLeftPush(key, values, callback);","handlingStrategy":"validation","validationCode":"if (elements is null || !elements.Any()) return; // or throw a clearer error at the caller\nclient.ListLeftPush(key, elements, callback);","typeGuard":"bool HasElements(IEnumerable<string> e) => e is not null && e.Any();","tryCatchPattern":null,"preventionTips":["Check elements.Any() before ListLeftPush.","Skip the push when there is nothing to add.","Prefer the async params overload where possible for the cleaner guard."],"tags":["csharp","validation","list-commands","argument","garnet-client"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}