Skip to content

Commit

Permalink
1. SKException is cnhanged to be instantiable and public.
Browse files Browse the repository at this point in the history
2. AzureSearchMemoryException is removed.
  • Loading branch information
SergeyMenshykh committed Jul 18, 2023
1 parent 95d672a commit 32d5d56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 100 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.Models;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;

namespace Microsoft.SemanticKernel.Connectors.Memory.AzureSearch;
Expand Down Expand Up @@ -113,9 +114,7 @@ public async IAsyncEnumerable<string> UpsertBatchAsync(string collectionName, IE

if (result?.Value == null)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.ReadFailure,
"Memory read returned null");
throw new SKException("Memory read returned null");
}

return result.Value.ToMemoryRecord();
Expand Down Expand Up @@ -246,9 +245,7 @@ public async Task RemoveBatchAsync(string collectionName, IEnumerable<string> ke
{
if (embeddingSize < 1)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.InvalidEmbeddingSize,
"Invalid embedding size: the value must be greater than zero.");
throw new SKException("Invalid embedding size: the value must be greater than zero.");
}

var configName = "searchConfig";
Expand Down Expand Up @@ -336,9 +333,7 @@ Task<Response<IndexDocumentsResult>> UpsertCode()

if (result == null || result.Value.Results.Count == 0)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.WriteFailure,
"Memory write returned null or an empty set");
throw new SKException("Memory write returned null or an empty set");
}

return result.Value.Results.Select(x => x.Key).ToList();
Expand All @@ -355,9 +350,7 @@ private string NormalizeIndexName(string indexName)
{
if (indexName.Length > 128)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.InvalidIndexName,
"The collection name is too long, it cannot exceed 128 chars.");
throw new SKException("The collection name is too long, it cannot exceed 128 chars.");
}

#pragma warning disable CA1308 // The service expects a lowercase string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ internal static class ExceptionExtensions
/// <param name="ex">Exception.</param>
/// <returns>True if <paramref name="ex"/> is a critical exception and should not be caught.</returns>
internal static bool IsCriticalException(this Exception ex)
=> ex is OutOfMemoryException
or ThreadAbortException
=> ex is ThreadAbortException
or AccessViolationException
or AppDomainUnloadedException
or BadImageFormatException
or CannotUnloadAppDomainException
or InvalidProgramException
or StackOverflowException;
or InvalidProgramException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace Microsoft.SemanticKernel.Diagnostics;
/// <summary>
/// Provides the base exception from which all Semantic Kernel exceptions derive.
/// </summary>
public abstract class SKException : Exception
public class SKException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="SKException"/> class with a default message.
/// </summary>
protected SKException()
public SKException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SKException"/> class with its message set to <paramref name="message"/>.
/// </summary>
/// <param name="message">A string that describes the error.</param>
protected SKException(string? message) : base(message)
public SKException(string? message) : base(message)
{
}

Expand All @@ -29,7 +29,7 @@ protected SKException(string? message) : base(message)
/// </summary>
/// <param name="message">A string that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
protected SKException(string? message, Exception? innerException) : base(message, innerException)
public SKException(string? message, Exception? innerException) : base(message, innerException)
{
}
}

0 comments on commit 32d5d56

Please sign in to comment.