Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BlobStorageAdapter.cs): supress error "BlobNotFound" and return … #208

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
35 changes: 24 additions & 11 deletions src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Azure.Storage.Blobs.Models;
using Azure;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Sas;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -33,7 +34,7 @@

foreach (var tag in tags)
{
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";

Check warning on line 37 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.

Check warning on line 37 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.
}

stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);
Expand All @@ -43,7 +44,7 @@
var blockBlob = client.GetBlockBlobClient(blobItem.BlobName);

await blockBlob.DeleteAsync();
};

Check warning on line 47 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Remove this empty statement.

Check warning on line 47 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Remove this empty statement.
}

///<inheritdoc/>
Expand Down Expand Up @@ -89,7 +90,7 @@
var stringFilter = string.Empty;
foreach (var tag in tags)
{
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";

Check warning on line 93 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.

Check warning on line 93 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.
}
stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);

Expand Down Expand Up @@ -129,19 +130,31 @@
///<inheritdoc/>
public async Task<LiquidBlob> ReadBlobsByName(string blobName, string containerName)
{
var client = _factory.GetContainerClient(containerName);
try
{
var client = _factory.GetContainerClient(containerName);
var blockBlob = client.GetBlockBlobClient(blobName);
var blob = await blockBlob.DownloadContentAsync();
var item = new LiquidBlob
{
Blob = blob.Value.Content.ToArray(),
Tags = blockBlob.GetTags().Value.Tags,
Name = blobName,
AbsoluteUri = blockBlob.Uri.AbsoluteUri
};

var blockBlob = client.GetBlockBlobClient(blobName);
var blob = await blockBlob.DownloadContentAsync();
var item = new LiquidBlob
return item;
}
catch (RequestFailedException storageRequestFailedException)
when (storageRequestFailedException.ErrorCode == BlobErrorCode.BlobNotFound)
{
Blob = blob.Value.Content.ToArray(),
Tags = blockBlob.GetTags().Value.Tags,
Name = blobName,
AbsoluteUri = blockBlob.Uri.AbsoluteUri
};
return null;

Check warning on line 151 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Possible null reference return.

Check warning on line 151 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Possible null reference return.
}
catch (Exception)

Check warning on line 153 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Add logic to this catch clause or eliminate it and rethrow the exception automatically.

Check warning on line 153 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Add logic to this catch clause or eliminate it and rethrow the exception automatically.
{
throw;
}

return item;
}

///<inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Company>Avanade Inc.</Company>
<Product>Liquid - Modern Application Framework</Product>
<Copyright>Avanade 2019</Copyright>
<Version>6.0.0-preview-20221201-03</Version>
<Version>6.0.0-preview-20221201-04</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<Description>
Expand Down
Loading