Skip to content

Commit 86983f7

Browse files
author
Milder Hernandez
authored
Merge pull request #196 from milderhc/exceptions
Update to SKException
2 parents 38c0b70 + d84027f commit 86983f7

15 files changed

Lines changed: 44 additions & 36 deletions

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/azureaisearch/AzureAISearchVectorStoreCollectionCreateMapping.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDataField;
1414
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordKeyField;
1515
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordVectorField;
16+
import com.microsoft.semantickernel.exceptions.SKException;
17+
1618
import java.time.OffsetDateTime;
1719
import java.util.List;
1820
import javax.annotation.Nonnull;
@@ -41,7 +43,7 @@ private static VectorSearchAlgorithmMetric getAlgorithmMetric(
4143
case EUCLIDEAN:
4244
return VectorSearchAlgorithmMetric.EUCLIDEAN;
4345
default:
44-
throw new IllegalArgumentException(
46+
throw new SKException(
4547
"Unsupported distance function: " + vectorField.getDistanceFunction());
4648
}
4749
}
@@ -62,7 +64,7 @@ private static VectorSearchAlgorithmConfiguration getAlgorithmConfig(
6264
.setParameters(
6365
new ExhaustiveKnnParameters().setMetric(getAlgorithmMetric(vectorField)));
6466
default:
65-
throw new IllegalArgumentException(
67+
throw new SKException(
6668
"Unsupported index kind: " + vectorField.getIndexKind());
6769
}
6870
}
@@ -75,7 +77,7 @@ public static SearchField mapKeyField(VectorStoreRecordKeyField keyField) {
7577

7678
public static SearchField mapDataField(VectorStoreRecordDataField dataField) {
7779
if (dataField.getFieldType() == null) {
78-
throw new IllegalArgumentException(
80+
throw new SKException(
7981
"Field type is required: " + dataField.getEffectiveStorageName());
8082
}
8183

@@ -97,7 +99,7 @@ public static void updateVectorSearchParameters(
9799
List<VectorSearchProfile> profiles,
98100
VectorStoreRecordVectorField vectorField) {
99101
if (vectorField.getDimensions() <= 0) {
100-
throw new IllegalArgumentException("Vector field dimensions must be greater than 0");
102+
throw new SKException("Vector field dimensions must be greater than 0");
101103
}
102104

103105
algorithms.add(getAlgorithmConfig(vectorField));
@@ -121,7 +123,7 @@ public static SearchFieldDataType getSearchFieldDataType(Class<?> fieldType) {
121123
} else if (fieldType == OffsetDateTime.class) {
122124
return SearchFieldDataType.DATE_TIME_OFFSET;
123125
} else {
124-
throw new IllegalArgumentException("Unsupported field type: " + fieldType.getName());
126+
throw new SKException("Unsupported field type: " + fieldType.getName());
125127
}
126128
}
127129
}

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/azureaisearch/AzureAISearchVectorStoreRecordCollectionOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.microsoft.semantickernel.data.VectorStoreRecordCollectionOptions;
66
import com.microsoft.semantickernel.data.VectorStoreRecordMapper;
77
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDefinition;
8+
import com.microsoft.semantickernel.exceptions.SKException;
9+
810
import javax.annotation.Nonnull;
911
import javax.annotation.Nullable;
1012

@@ -128,7 +130,7 @@ public Builder<Record> withRecordDefinition(VectorStoreRecordDefinition recordDe
128130
*/
129131
public AzureAISearchVectorStoreRecordCollectionOptions<Record> build() {
130132
if (recordClass == null) {
131-
throw new IllegalArgumentException("recordClass must be provided");
133+
throw new SKException("recordClass must be provided");
132134
}
133135

134136
return new AzureAISearchVectorStoreRecordCollectionOptions<>(

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public JDBCVectorStore build() {
162162
*/
163163
public Mono<JDBCVectorStore> buildAsync() {
164164
if (dataSource == null) {
165-
throw new IllegalArgumentException("dataSource is required");
165+
throw new SKException("dataSource is required");
166166
}
167167

168168
JDBCVectorStore vectorStore = new JDBCVectorStore(dataSource, options);

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreDefaultQueryProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void prepareVectorStore() {
182182
* Checks if the types of the record class fields are supported.
183183
*
184184
* @param recordDefinition the record definition
185-
* @throws IllegalArgumentException if the types are not supported
185+
* @throws SKException if the types are not supported
186186
*/
187187
@Override
188188
public void validateSupportedTypes(VectorStoreRecordDefinition recordDefinition) {
@@ -403,13 +403,13 @@ public void deleteRecords(String collectionName, List<String> keys,
403403
*
404404
* @param identifier the identifier
405405
* @return the identifier if it is valid
406-
* @throws IllegalArgumentException if the identifier is invalid
406+
* @throws SKException if the identifier is invalid
407407
*/
408408
public static String validateSQLidentifier(String identifier) {
409409
if (identifier.matches("[a-zA-Z_][a-zA-Z0-9_]*")) {
410410
return identifier;
411411
}
412-
throw new IllegalArgumentException("Invalid SQL identifier: " + identifier);
412+
throw new SKException("Invalid SQL identifier: " + identifier);
413413
}
414414

415415
/**
@@ -455,7 +455,7 @@ public Builder withPrefixForCollectionTables(String prefixForCollectionTables) {
455455
@Override
456456
public JDBCVectorStoreDefaultQueryProvider build() {
457457
if (dataSource == null) {
458-
throw new IllegalArgumentException("DataSource is required");
458+
throw new SKException("DataSource is required");
459459
}
460460

461461
return new JDBCVectorStoreDefaultQueryProvider(dataSource, collectionsTable,

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreRecordCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ public Builder<Record> withOptions(JDBCVectorStoreRecordCollectionOptions<Record
329329
@Override
330330
public JDBCVectorStoreRecordCollection<Record> build() {
331331
if (dataSource == null) {
332-
throw new IllegalArgumentException("dataSource is required");
332+
throw new SKException("dataSource is required");
333333
}
334334
if (collectionName == null) {
335-
throw new IllegalArgumentException("collectionName is required");
335+
throw new SKException("collectionName is required");
336336
}
337337
if (options == null) {
338-
throw new IllegalArgumentException("options is required");
338+
throw new SKException("options is required");
339339
}
340340

341341
return new JDBCVectorStoreRecordCollection<>(dataSource, collectionName, options);

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreRecordCollectionOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.microsoft.semantickernel.data.VectorStoreRecordCollectionOptions;
55
import com.microsoft.semantickernel.data.VectorStoreRecordMapper;
66
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDefinition;
7+
import com.microsoft.semantickernel.exceptions.SKException;
78
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
89

910
import java.sql.ResultSet;
@@ -180,7 +181,7 @@ public Builder<Record> withPrefixForCollectionTables(String prefixForCollectionT
180181
*/
181182
public JDBCVectorStoreRecordCollectionOptions<Record> build() {
182183
if (recordClass == null) {
183-
throw new IllegalArgumentException("recordClass is required");
184+
throw new SKException("recordClass is required");
184185
}
185186

186187
return new JDBCVectorStoreRecordCollectionOptions<>(

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreRecordMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ public Builder<Record> withObjectMapper(ObjectMapper objectMapper) {
9797
*/
9898
public JDBCVectorStoreRecordMapper<Record> build() {
9999
if (recordClass == null) {
100-
throw new IllegalArgumentException("recordClass is required");
100+
throw new SKException("recordClass is required");
101101
}
102102
if (vectorStoreRecordDefinition == null) {
103-
throw new IllegalArgumentException("vectorStoreRecordDefinition is required");
103+
throw new SKException("vectorStoreRecordDefinition is required");
104104
}
105105

106106
return new JDBCVectorStoreRecordMapper<>(

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/postgres/PostgreSQLVectorStoreRecordMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1515
import org.postgresql.util.PGobject;
1616

17-
import java.lang.reflect.Constructor;
18-
import java.lang.reflect.Field;
19-
import java.lang.reflect.InvocationTargetException;
2017
import java.sql.ResultSet;
2118
import java.sql.ResultSetMetaData;
2219
import java.sql.SQLException;
@@ -94,10 +91,10 @@ public Builder<Record> withObjectMapper(ObjectMapper objectMapper) {
9491
*/
9592
public PostgreSQLVectorStoreRecordMapper<Record> build() {
9693
if (recordClass == null) {
97-
throw new IllegalArgumentException("recordClass is required");
94+
throw new SKException("recordClass is required");
9895
}
9996
if (vectorStoreRecordDefinition == null) {
100-
throw new IllegalArgumentException("vectorStoreRecordDefinition is required");
97+
throw new SKException("vectorStoreRecordDefinition is required");
10198
}
10299

103100
return new PostgreSQLVectorStoreRecordMapper<>(

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/redis/RedisHashSetVectorStoreRecordCollectionOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.microsoft.semantickernel.data.VectorStoreRecordCollectionOptions;
55
import com.microsoft.semantickernel.data.VectorStoreRecordMapper;
66
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDefinition;
7+
import com.microsoft.semantickernel.exceptions.SKException;
78

89
import javax.annotation.Nonnull;
910
import javax.annotation.Nullable;
@@ -155,7 +156,7 @@ public Builder<Record> withPrefixCollectionName(boolean prefixCollectionName) {
155156
*/
156157
public RedisHashSetVectorStoreRecordCollectionOptions<Record> build() {
157158
if (recordClass == null) {
158-
throw new IllegalArgumentException("recordClass must be provided");
159+
throw new SKException("recordClass must be provided");
159160
}
160161

161162
return new RedisHashSetVectorStoreRecordCollectionOptions<>(

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/redis/RedisHashSetVectorStoreRecordMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public Builder<Record> withVectorStoreRecordDefinition(
8484
@Override
8585
public RedisHashSetVectorStoreRecordMapper<Record> build() {
8686
if (recordClass == null) {
87-
throw new IllegalArgumentException("recordClass is required");
87+
throw new SKException("recordClass is required");
8888
}
8989
if (recordDefinition == null) {
90-
throw new IllegalArgumentException("vectorStoreRecordDefinition is required");
90+
throw new SKException("vectorStoreRecordDefinition is required");
9191
}
9292

9393
ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)