Skip to content

Commit 700e96b

Browse files
authored
Revisit error messages for readability (#430)
Use new error helpers to provide better error messages and reduce code, compatibly with .NET Standard 2.0. Change exceptions and messages used during validation. Upgrade packages
1 parent d5957cf commit 700e96b

65 files changed

Lines changed: 208 additions & 313 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Packages.props

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
</ItemGroup>
4343
<!-- Kernel Memory -->
4444
<ItemGroup>
45-
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.36.240416.1" />
46-
<PackageVersion Include="Microsoft.KernelMemory.Core" Version="0.36.240416.1" />
45+
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.37.240423.2" />
46+
<PackageVersion Include="Microsoft.KernelMemory.Core" Version="0.37.240420.2" />
4747
<PackageVersion Include="KernelMemory.MemoryStorage.SqlServer" Version="1.6.3" />
4848
<PackageVersion Include="FreeMindLabs.KernelMemory.Elasticsearch" Version="0.9.5" />
4949
</ItemGroup>
5050
<!-- Semantic Kernel -->
5151
<ItemGroup>
52-
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.7.1" />
53-
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.7.1" />
52+
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.8.0" />
53+
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.8.0" />
5454
</ItemGroup>
5555
<!-- Documentation -->
5656
<ItemGroup>
@@ -65,11 +65,11 @@
6565
</PackageVersion>
6666
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
6767
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28" />
68-
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.1">
68+
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.2">
6969
<PrivateAssets>all</PrivateAssets>
7070
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7171
</PackageVersion>
72-
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.1">
72+
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.2">
7373
<PrivateAssets>all</PrivateAssets>
7474
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7575
</PackageVersion>

clients/dotnet/WebClient/Internals/Verify.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ static bool IsReservedIpAddress(string host)
2424
host.StartsWith("255.255.255.255", StringComparison.Ordinal);
2525
}
2626

27-
if (string.IsNullOrEmpty(url))
28-
{
29-
throw new ArgumentException("The URL is empty");
30-
}
27+
ArgumentNullExceptionEx.ThrowIfNullOrEmpty(url, nameof(url), "The URL is empty");
3128

3229
if (requireHttps && url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
3330
{

examples/002-dotnet-SemanticKernel-plugin/002-dotnet-SemanticKernel-plugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.7.1" />
12+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.8.0" />
1313
<PackageReference Include="Microsoft.KernelMemory.SemanticKernelPlugin" Version="0.37.240420.2" />
1414
</ItemGroup>
1515

examples/106-dotnet-retrieve-synthetics/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ await memory.ImportDocumentAsync(new Document("doc1")
3939
// Fetch the list of summaries. The API returns one summary for each file.
4040
var results = await memory.SearchSummariesAsync(filter: MemoryFilters.ByDocument("doc1"));
4141

42-
// Print the summaries!
42+
// Print the summaries
4343
foreach (var result in results)
4444
{
4545
Console.WriteLine($"== {result.SourceName} summary ==\n{result.Partitions.First().Text}\n");

extensions/AzureAIDocIntel/AzureAIDocIntelConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public void Validate()
3030
{
3131
if (this.Auth == AuthTypes.APIKey && string.IsNullOrWhiteSpace(this.APIKey))
3232
{
33-
throw new ArgumentOutOfRangeException(nameof(this.APIKey), "The API Key is empty");
33+
throw new ConfigurationException($"Azure AI Document Intelligence: {nameof(this.APIKey)} is empty");
3434
}
3535

3636
if (string.IsNullOrWhiteSpace(this.Endpoint))
3737
{
38-
throw new ArgumentOutOfRangeException(nameof(this.Endpoint), "The endpoint value is empty");
38+
throw new ConfigurationException($"Azure AI Document Intelligence: {nameof(this.Endpoint)} is empty");
3939
}
4040

4141
if (!this.Endpoint.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
4242
{
43-
throw new ArgumentOutOfRangeException(nameof(this.Endpoint), "The endpoint value must start with https://");
43+
throw new ConfigurationException($"Azure AI Document Intelligence: {nameof(this.Endpoint)} must start with https://");
4444
}
4545
}
4646
}

extensions/AzureAIDocIntel/AzureAIDocIntelEngine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Azure.AI.FormRecognizer.DocumentAnalysis;
99
using Azure.Identity;
1010
using Microsoft.Extensions.Logging;
11-
using Microsoft.KernelMemory.Configuration;
1211
using Microsoft.KernelMemory.Diagnostics;
1312

1413
namespace Microsoft.KernelMemory.DataFormats.AzureAIDocIntel;

extensions/AzureAISearch/AzureAISearch.TestApplication/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static async Task Main()
3535
.AddJsonFile("appsettings.Development.json", optional: true)
3636
.Build();
3737

38-
var config = cfg.GetSection("KernelMemory:Services:AzureAISearch").Get<AzureAISearchConfig>()
39-
?? throw new ArgumentNullException(message: "AzureAISearch config not found", null);
38+
var config = cfg.GetSection("KernelMemory:Services:AzureAISearch").Get<AzureAISearchConfig>();
39+
ArgumentNullExceptionEx.ThrowIfNull(config, nameof(config), "AzureAISearch config not found");
4040

4141
// Azure AI Search service client
4242
s_adminClient = new SearchIndexClient(

extensions/AzureAISearch/AzureAISearch/AzureAISearchConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using System.Text.Json.Serialization;
44
using Azure.Core;
5-
using Microsoft.KernelMemory.Configuration;
65

76
#pragma warning disable IDE0130 // reduce number of "using" statements
87
// ReSharper disable once CheckNamespace - reduce number of "using" statements
@@ -35,6 +34,6 @@ public void SetCredential(TokenCredential credential)
3534
public TokenCredential GetTokenCredential()
3635
{
3736
return this._tokenCredential
38-
?? throw new ConfigurationException("TokenCredential not defined");
37+
?? throw new ConfigurationException($"Azure AI Search: {nameof(this._tokenCredential)} not defined");
3938
}
4039
}

extensions/AzureAISearch/AzureAISearch/AzureAISearchMemory.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Azure.Search.Documents.Models;
1717
using Microsoft.Extensions.Logging;
1818
using Microsoft.KernelMemory.AI;
19-
using Microsoft.KernelMemory.Configuration;
2019
using Microsoft.KernelMemory.ContentStorage;
2120
using Microsoft.KernelMemory.Diagnostics;
2221
using Microsoft.KernelMemory.MemoryStorage;
@@ -53,12 +52,12 @@ public AzureAISearchMemory(
5352
if (string.IsNullOrEmpty(config.Endpoint))
5453
{
5554
this._log.LogCritical("Azure AI Search Endpoint is empty");
56-
throw new ConfigurationException("Azure AI Search Endpoint is empty");
55+
throw new ConfigurationException($"Azure AI Search: {nameof(config.Endpoint)} is empty");
5756
}
5857

5958
if (this._embeddingGenerator == null)
6059
{
61-
throw new AzureAISearchMemoryException("Embedding generator not configured");
60+
throw new ConfigurationException($"Azure AI Search: {nameof(this._embeddingGenerator)} is not configured");
6261
}
6362

6463
switch (config.Auth)
@@ -74,7 +73,7 @@ public AzureAISearchMemory(
7473
if (string.IsNullOrEmpty(config.APIKey))
7574
{
7675
this._log.LogCritical("Azure AI Search API key is empty");
77-
throw new ConfigurationException("Azure AI Search API key is empty");
76+
throw new ConfigurationException($"Azure AI Search: {nameof(config.APIKey)} is empty");
7877
}
7978

8079
this._adminClient = new SearchIndexClient(
@@ -431,10 +430,7 @@ private static SearchClientOptions GetClientOptions()
431430
/// <returns>Normalized name</returns>
432431
private string NormalizeIndexName(string index)
433432
{
434-
if (string.IsNullOrWhiteSpace(index))
435-
{
436-
throw new ArgumentNullException(nameof(index), "The index name is empty");
437-
}
433+
ArgumentNullExceptionEx.ThrowIfNullOrWhiteSpace(index, nameof(index), "The index name is empty");
438434

439435
if (index.Length > 128)
440436
{

extensions/AzureBlobs/AzureBlobsConfig.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Azure;
55
using Azure.Core;
66
using Azure.Storage;
7-
using Microsoft.KernelMemory.Configuration;
87

98
#pragma warning disable IDE0130 // reduce number of "using" statements
109
// ReSharper disable once CheckNamespace - reduce number of "using" statements
@@ -57,18 +56,18 @@ public void SetCredential(TokenCredential credential)
5756
public StorageSharedKeyCredential GetStorageSharedKeyCredential()
5857
{
5958
return this._storageSharedKeyCredential
60-
?? throw new ConfigurationException("StorageSharedKeyCredential not defined");
59+
?? throw new ConfigurationException($"Azure Blobs: {nameof(this._storageSharedKeyCredential)} not defined");
6160
}
6261

6362
public AzureSasCredential GetAzureSasCredential()
6463
{
6564
return this._azureSasCredential
66-
?? throw new ConfigurationException("AzureSasCredential not defined");
65+
?? throw new ConfigurationException($"Azure Blobs: {nameof(this._azureSasCredential)} not defined");
6766
}
6867

6968
public TokenCredential GetTokenCredential()
7069
{
7170
return this._tokenCredential
72-
?? throw new ConfigurationException("TokenCredential not defined");
71+
?? throw new ConfigurationException($"Azure Blobs: {nameof(this._tokenCredential)} not defined");
7372
}
7473
}

0 commit comments

Comments
 (0)