Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/Extensions/AzureBlobPayloads/PayloadStore/BlobPayloadStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License.

using System.IO.Compression;
using System.Net;
using System.Text;
using Azure;
using Azure.Core;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
Expand Down Expand Up @@ -117,20 +119,30 @@ public override async Task<string> DownloadAsync(string token, CancellationToken

BlobClient blob = this.containerClient.GetBlobClient(name);

using BlobDownloadStreamingResult result = await blob.DownloadStreamingAsync(cancellationToken: cancellationToken);
Stream contentStream = result.Content;
bool isGzip = string.Equals(
result.Details.ContentEncoding, ContentEncodingGzip, StringComparison.OrdinalIgnoreCase);
try
{
using BlobDownloadStreamingResult result = await blob.DownloadStreamingAsync(cancellationToken: cancellationToken);
Stream contentStream = result.Content;
bool isGzip = string.Equals(
result.Details.ContentEncoding, ContentEncodingGzip, StringComparison.OrdinalIgnoreCase);

if (isGzip)
{
using GZipStream decompressed = new(contentStream, CompressionMode.Decompress);
using StreamReader reader = new(decompressed, Encoding.UTF8);
return await ReadToEndAsync(reader, cancellationToken);
}

if (isGzip)
using StreamReader uncompressedReader = new(contentStream, Encoding.UTF8);
return await ReadToEndAsync(uncompressedReader, cancellationToken);
}
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
{
using GZipStream decompressed = new(contentStream, CompressionMode.Decompress);
using StreamReader reader = new(decompressed, Encoding.UTF8);
return await ReadToEndAsync(reader, cancellationToken);
throw new InvalidOperationException(
$"The blob '{name}' was not found in container '{container}'. " +
"The payload may have been deleted or the container was never created.",
ex);
}
Comment on lines +139 to 145
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new exception handling logic for 404 errors in DownloadAsync lacks test coverage. Consider adding a test that verifies:

  1. A RequestFailedException with 404 status is properly caught
  2. The resulting InvalidOperationException contains the expected error message with blob name and container
  3. The original RequestFailedException is preserved as the inner exception

This would ensure the error handling behavior is maintained across future changes.

Copilot uses AI. Check for mistakes.

using StreamReader uncompressedReader = new(contentStream, Encoding.UTF8);
return await ReadToEndAsync(uncompressedReader, cancellationToken);
}

/// <inheritdoc/>
Expand Down
Loading