Skip to content

Commit c6c4fea

Browse files
committed
Throw empty list when passing empty list to index
1 parent 9cde514 commit c6c4fea

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointIndexingImpl.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.algolia.search.endpoint
33
import com.algolia.search.client.Index
44
import com.algolia.search.configuration.CallType
55
import com.algolia.search.dsl.requestOptionsBuilder
6+
import com.algolia.search.exception.EmptyListException
67
import com.algolia.search.helper.toIndexName
78
import com.algolia.search.model.Attribute
89
import com.algolia.search.model.IndexName
@@ -203,6 +204,7 @@ internal class EndpointIndexingImpl(
203204
batchOperations: List<BatchOperation>,
204205
requestOptions: RequestOptions?
205206
): ResponseBatch {
207+
if (batchOperations.isEmpty()) throw EmptyListException("batchOperations")
206208
val requests = Json.toJson(BatchOperation.list, batchOperations)
207209
val body = json { KeyRequests to requests }.toString()
208210

@@ -231,6 +233,7 @@ internal class EndpointIndexingImpl(
231233
}
232234

233235
private suspend fun replaceAllObjectsInternal(batchOperations: List<BatchOperation>): List<TaskIndex> {
236+
if (batchOperations.isEmpty()) throw EmptyListException("batchOperations")
234237
val indexSource = Index(transport, indexName)
235238
val indexDestination = Index(transport, "${indexName}_tmp_${Random.nextInt()}".toIndexName())
236239
val scopes = listOf(Scope.Settings, Scope.Rules, Scope.Synonyms)

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointMultipleIndexImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.algolia.search.endpoint
22

33
import com.algolia.search.configuration.CallType
4+
import com.algolia.search.exception.EmptyListException
45
import com.algolia.search.model.multipleindex.BatchOperationIndex
56
import com.algolia.search.model.multipleindex.IndexQuery
67
import com.algolia.search.model.multipleindex.MultipleQueriesStrategy
@@ -50,6 +51,7 @@ internal class EndpointMultipleIndexImpl(
5051
operations: List<BatchOperationIndex>,
5152
requestOptions: RequestOptions?
5253
): ResponseBatches {
54+
if (operations.isEmpty()) throw EmptyListException("operations")
5355
val requests = Json.toJson(BatchOperationIndex.list, operations)
5456
val body = json { KeyRequests to requests }.toString()
5557

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointRuleImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.algolia.search.endpoint
22

33
import com.algolia.search.configuration.CallType
44
import com.algolia.search.dsl.requestOptionsBuilder
5+
import com.algolia.search.exception.EmptyListException
56
import com.algolia.search.model.IndexName
67
import com.algolia.search.model.ObjectID
78
import com.algolia.search.model.response.ResponseSearchRules
@@ -79,6 +80,7 @@ internal class EndpointRuleImpl(
7980
clearExistingRules: Boolean?,
8081
requestOptions: RequestOptions?
8182
): RevisionIndex {
83+
if (rules.isEmpty()) throw EmptyListException("rules")
8284
val body = JsonNoDefaults.stringify(Rule.serializer().list, rules)
8385
val options = requestOptionsBuilder(requestOptions) {
8486
parameter(KeyForwardToReplicas, forwardToReplicas)

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointSynonymImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.algolia.search.endpoint
22

33
import com.algolia.search.configuration.CallType
44
import com.algolia.search.dsl.requestOptionsBuilder
5+
import com.algolia.search.exception.EmptyListException
56
import com.algolia.search.model.IndexName
67
import com.algolia.search.model.ObjectID
78
import com.algolia.search.model.response.ResponseSearchSynonyms
@@ -42,6 +43,7 @@ internal class EndpointSynonymImpl(
4243
replaceExistingSynonyms: Boolean?,
4344
requestOptions: RequestOptions?
4445
): RevisionIndex {
46+
if (synonyms.isEmpty()) throw EmptyListException("synonyms")
4547
val path = indexName.toPath("/$RouteSynonyms/batch")
4648
val body = Json.stringify(Synonym.list, synonyms)
4749
val options = requestOptionsBuilder(requestOptions) {

0 commit comments

Comments
 (0)