55
66namespace Microsoft . SemanticKernel . Connectors . Memory . Qdrant . Diagnostics ;
77
8+ #pragma warning disable CA1032 // Implement standard exception constructors
9+
810/// <summary>
9- /// Custom exceptions for the Qdrant connector.
11+ /// Exception thrown for errors related to the Qdrant connector.
1012/// </summary>
11- public class QdrantMemoryException : Exception < QdrantMemoryException . ErrorCodes >
13+ public class QdrantMemoryException : SKException
1214{
15+ /// <summary>
16+ /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with a provided error code.
17+ /// </summary>
18+ /// <param name="errorCode">The error code.</param>
19+ public QdrantMemoryException ( ErrorCodes errorCode )
20+ : this ( errorCode , message : null , innerException : null )
21+ {
22+ }
23+
24+ /// <summary>
25+ /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with a provided error code and message.
26+ /// </summary>
27+ /// <param name="errorCode">The error code.</param>
28+ /// <param name="message">The exception message.</param>
29+ public QdrantMemoryException ( ErrorCodes errorCode , string ? message )
30+ : this ( errorCode , message , innerException : null )
31+ {
32+ }
33+
34+ /// <summary>
35+ /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with a provided error code and inner exception.
36+ /// </summary>
37+ /// <param name="errorCode">The error code.</param>
38+ /// <param name="innerException">The exception that is the cause of the current exception.</param>
39+ public QdrantMemoryException ( ErrorCodes errorCode , Exception ? innerException )
40+ : this ( errorCode , message : null , innerException )
41+ {
42+ }
43+
44+ /// <summary>
45+ /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with a provided error code, message, and inner exception.
46+ /// </summary>
47+ /// <param name="errorCode">The error code.</param>
48+ /// <param name="message">A string that describes the error.</param>
49+ /// <param name="innerException">The exception that is the cause of the current exception.</param>
50+ public QdrantMemoryException ( ErrorCodes errorCode , string ? message , Exception ? innerException )
51+ : base ( GetDefaultMessage ( errorCode , message , innerException ) , innerException )
52+ {
53+ this . ErrorCode = errorCode ;
54+ }
55+
56+ /// <summary>
57+ /// Gets the error code for this exception.
58+ /// </summary>
59+ public ErrorCodes ErrorCode { get ; }
60+
61+ /// <summary>Translate the error code into a default message.</summary>
62+ private static string GetDefaultMessage ( ErrorCodes errorCode , string ? message , Exception ? innerException )
63+ {
64+ if ( message is not null )
65+ {
66+ return message ;
67+ }
68+
69+ string description = errorCode switch
70+ {
71+ ErrorCodes . UnableToDeserializeRecordPayload => "Unable to deserialize record payload" ,
72+ ErrorCodes . FailedToUpsertVectors => "Failed to upsert vectors" ,
73+ ErrorCodes . FailedToGetVectorData => "Failed to get vector data" ,
74+ ErrorCodes . FailedToRemoveVectorData => "Failed to remove vector data" ,
75+ ErrorCodes . FailedToConvertMemoryRecordToQdrantVectorRecord => "Failed to convert memory record to Qdrant vector record" ,
76+ ErrorCodes . FailedToConvertQdrantVectorRecordToMemoryRecord => "Failed to convert Qdrant vector record to memory record" ,
77+ _ => $ "Unknown error ({ errorCode : G} )",
78+ } ;
79+
80+ return innerException is not null ? $ "{ description } : { innerException . Message } " : description ;
81+ }
82+
1383 /// <summary>
1484 /// Error codes for the Qdrant connector exceptions.
1585 /// </summary>
@@ -18,7 +88,7 @@ public enum ErrorCodes
1888 /// <summary>
1989 /// Unknown error.
2090 /// </summary>
21- UnknownError ,
91+ UnknownError = - 1 ,
2292
2393 /// <summary>
2494 /// Failed to deserialize the record payload.
@@ -50,47 +120,4 @@ public enum ErrorCodes
50120 /// </summary>
51121 FailedToConvertQdrantVectorRecordToMemoryRecord
52122 }
53-
54- /// <summary>
55- /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with error code unknown.
56- /// </summary>
57- /// <param name="message">The exception message.</param>
58- public QdrantMemoryException ( string message )
59- : this ( ErrorCodes . UnknownError , message )
60- {
61- }
62-
63- /// <summary>
64- /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with a provided error code.
65- /// </summary>
66- /// <param name="error">The error code.</param>
67- /// <param name="message">The exception message.</param>
68- public QdrantMemoryException ( ErrorCodes error , string message )
69- : base ( error , message )
70- {
71- }
72-
73- /// <summary>
74- /// Initializes a new instance of the <see cref="QdrantMemoryException"/> class with an inner exception.
75- /// </summary>
76- /// <param name="error">The error code.</param>
77- /// <param name="message">The exception message.</param>
78- /// <param name="innerException">The inner exception</param>
79- public QdrantMemoryException ( ErrorCodes error , string message , Exception innerException )
80- : base ( BuildMessage ( error , message ) , innerException )
81- {
82- }
83-
84- private QdrantMemoryException ( )
85- {
86- }
87-
88- private static string BuildMessage ( ErrorCodes error , string ? message )
89- {
90- return message != null ? $ "{ error . ToString ( "G" ) } : { message } " : error . ToString ( "G" ) ;
91- }
92-
93- private QdrantMemoryException ( string message , System . Exception innerException ) : base ( message , innerException )
94- {
95- }
96123}
0 commit comments