dotnet/orleans · info · InvalidOperationException
Unable to retrieve messages from the queue.
Error message
Unable to retrieve messages from the queue.
What it means
This is a structurally unreachable trailing throw in GetMessages. The try block either returns response.Messages or throws; any exception is caught and ReportErrorAndRethrow always rethrows as an AggregateException. Because the catch path never returns normally, control can never fall through to this final throw. It exists only to satisfy the compiler that the method returns a value on all paths.
Source
Thrown at src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs:203
public async Task<IEnumerable<SQSMessage>> GetMessages(int count = 1)
{
try
{
if (string.IsNullOrWhiteSpace(queueUrl))
throw new InvalidOperationException("Queue not initialized");
if (count < 1)
throw new ArgumentOutOfRangeException(nameof(count));
var request = new ReceiveMessageRequest { QueueUrl = queueUrl, MaxNumberOfMessages = count <= MAX_NUMBER_OF_MESSAGE_TO_PEEK ? count : MAX_NUMBER_OF_MESSAGE_TO_PEEK };
var response = await sqsClient.ReceiveMessageAsync(request);
return response.Messages;
}
catch (Exception exc)
{
ReportErrorAndRethrow(exc, "GetMessages");
}
throw new InvalidOperationException("Unable to retrieve messages from the queue.");
}
/// <summary>
/// Delete a message from SQS queue
/// </summary>
/// <param name="message">The message to be deleted</param>
/// <returns></returns>
public async Task DeleteMessage(SQSMessage message)
{
try
{
if (message == null)
throw new ArgumentNullException(nameof(message));
if (string.IsNullOrWhiteSpace(message.ReceiptHandle))
throw new ArgumentNullException(nameof(message.ReceiptHandle));
if (string.IsNullOrWhiteSpace(queueUrl))View on GitHub (pinned to fca799fa70)
Solutions
- Treat any 'Unable to retrieve messages from the queue.' sighting as misattributed; inspect the inner exception of the AggregateException from ReportErrorAndRethrow for the real cause.
- If you are maintaining this file, consider replacing the catch+throw tail with 'throw;' or marking ReportErrorAndRethrow as [DoesNotReturn] to remove the dead code.
- Fix the underlying SQS error (credentials, region, queue URL) that the wrapped exception reports.
Defensive patterns
Strategy: try-catch
Try / catch
// The trailing throw is unreachable; real failures surface as AggregateException.
try { var msgs = await storage.GetMessages(count); }
catch (AggregateException ex)
{
var root = ex.InnerExceptions.Count > 0 ? ex.InnerExceptions[0] : ex.InnerException;
logger.LogError(root, "GetMessages failed for queue {Queue}", storage.QueueName);
throw;
} Prevention
- Do not rely on this message as a real signal; inspect the AggregateException inner exception.
- If maintaining the file, annotate ReportErrorAndRethrow with [DoesNotReturn] to remove the dead throw.
- Report any genuine occurrence upstream as a provider bug.
When it happens
Trigger: Effectively unreachable in current code. It could only execute if ReportErrorAndRethrow were changed to stop throwing, or if the try block were edited to complete without returning.
Common situations: Developers see this message in a stack trace only when misattributing the real exception; the actual failure is the AggregateException from ReportErrorAndRethrow (e.g., network/AWS error). No realistic user action produces this exact throw.
Related errors
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/f25584e0692f1062.
Report an issue: GitHub.