{"record":{"id":"80d82c7c383b4f66","repo":"dotnet/orleans","slug":"count","errorCode":null,"errorMessage":"count","messagePattern":"count","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs","lineNumber":193,"sourceCode":"            {\n                ReportErrorAndRethrow(exc, \"AddMessage\");\n            }\n        }\n\n        /// <summary>\n        /// Get Messages from SQS Queue.\n        /// </summary>\n        /// <param name=\"count\">The number of messages to peak. Min 1 and max 10</param>\n        /// <returns>Collection with messages from the queue</returns>\n        public async Task<IEnumerable<SQSMessage>> GetMessages(int count = 1)\n        {\n            try\n            {\n                if (string.IsNullOrWhiteSpace(queueUrl))\n                    throw new InvalidOperationException(\"Queue not initialized\");\n\n                if (count < 1)\n                    throw new ArgumentOutOfRangeException(nameof(count));\n\n                var request = new ReceiveMessageRequest { QueueUrl = queueUrl, MaxNumberOfMessages = count <= MAX_NUMBER_OF_MESSAGE_TO_PEEK ? count : MAX_NUMBER_OF_MESSAGE_TO_PEEK };\n                var response = await sqsClient.ReceiveMessageAsync(request);\n                return response.Messages;\n            }\n            catch (Exception exc)\n            {\n                ReportErrorAndRethrow(exc, \"GetMessages\");\n            }\n            throw new InvalidOperationException(\"Unable to retrieve messages from the queue.\");\n        }\n\n        /// <summary>\n        /// Delete a message from SQS queue\n        /// </summary>\n        /// <param name=\"message\">The message to be deleted</param>\n        /// <returns></returns>\n        public async Task DeleteMessage(SQSMessage message)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs#L175-L211","documentation":"Thrown by SQSStorage.GetMessages when the requested count is less than 1. SQS ReceiveMessage requires at least one message per call, so the provider rejects zero or negative counts up front rather than forwarding an invalid MaxNumberOfMessages to AWS.","triggerScenarios":"Calling GetMessages(0), GetMessages(-1), or passing a computed/loop variable that underflows to <= 0. SQSAdapterReceiver paths that derive count from configuration or backpressure could feed 0 when the queue is idle.","commonSituations":"Passing an unconfigured option (default int 0) as the count; arithmetic that subtracts batch sizes and yields a negative remainder; porting code that treated 0 as 'use default' (the default is 1, so 0 must be passed explicitly).","solutions":["Pass a count >= 1; use the method default of 1 when you have no specific batch size.","Clamp the computed count: var take = Math.Max(1, requested); before calling GetMessages.","Audit SQSAdapterReceiver/configuration for any code path that can supply 0.","If 0 legitimately means 'nothing to do', short-circuit before calling GetMessages."],"exampleFix":"// before\nvar msgs = await storage.GetMessages(remaining); // remaining == 0 -> throws\n\n// after\nif (remaining < 1) return Enumerable.Empty<SQSMessage>();\nvar msgs = await storage.GetMessages(remaining);","handlingStrategy":"validation","validationCode":"if (count < 1) throw new ArgumentOutOfRangeException(nameof(count), count, \"must be >= 1\");\nvar take = Math.Min(count, SQSStorage.MAX_NUMBER_OF_MESSAGE_TO_PEEK);\nreturn await storage.GetMessages(take);","typeGuard":null,"tryCatchPattern":"try { return await storage.GetMessages(clamped); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"count\")\n{\n    logger.LogDebug(\"GetMessages called with count {Count}; clamping to 1.\", count);\n    return await storage.GetMessages(1);\n}","preventionTips":["Clamp computed batch sizes with Math.Max(1, value).","Short-circuit reads when the requested count is legitimately 0.","Treat 0 as a no-op at the caller, never forward it to GetMessages."],"tags":["aws","sqs","streaming","argument-validation","orleans"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}