Skip to content

Commit 7965afc

Browse files
reakaleekclaude
andcommitted
Search: Throw on failed async task start in ElasticsearchOperations
DeleteByQueryAsync, ReindexAsync, and UpdateByQueryAsync now throw InvalidOperationException when PostAsyncTaskAsync returns null instead of silently skipping the poll. These are wait-for-completion methods where callers expect the operation to have succeeded on return. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fc7c5cc commit 7965afc

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/Elastic.Markdown/Exporters/Elasticsearch/ElasticsearchOperations.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public async Task DeleteByQueryAsync(
156156
PostData query,
157157
CancellationToken ct)
158158
{
159-
var taskId = await DeleteByQueryFireAndForgetAsync(index, query, ct);
160-
if (taskId is not null)
161-
await PollTaskUntilCompleteAsync(taskId, "_delete_by_query", index, null, ct);
159+
var taskId = await DeleteByQueryFireAndForgetAsync(index, query, ct)
160+
?? throw new InvalidOperationException($"Failed to start _delete_by_query on {index}");
161+
await PollTaskUntilCompleteAsync(taskId, "_delete_by_query", index, null, ct);
162162
}
163163

164164
/// <summary>
@@ -171,9 +171,9 @@ public async Task ReindexAsync(
171171
CancellationToken ct)
172172
{
173173
var url = "/_reindex?wait_for_completion=false";
174-
var taskId = await PostAsyncTaskAsync(url, request, $"POST _reindex ({sourceIndex} => {destIndex})", ct);
175-
if (taskId is not null)
176-
await PollTaskUntilCompleteAsync(taskId, "_reindex", sourceIndex, destIndex, ct);
174+
var taskId = await PostAsyncTaskAsync(url, request, $"POST _reindex ({sourceIndex} => {destIndex})", ct)
175+
?? throw new InvalidOperationException($"Failed to start _reindex ({sourceIndex} => {destIndex})");
176+
await PollTaskUntilCompleteAsync(taskId, "_reindex", sourceIndex, destIndex, ct);
177177
}
178178

179179
/// <summary>
@@ -187,8 +187,8 @@ public async Task UpdateByQueryAsync(
187187
{
188188
var pipelineParam = pipeline is not null ? $"&pipeline={pipeline}" : "";
189189
var url = $"/{index}/_update_by_query?wait_for_completion=false{pipelineParam}";
190-
var taskId = await PostAsyncTaskAsync(url, query, $"POST {index}/_update_by_query", ct);
191-
if (taskId is not null)
192-
await PollTaskUntilCompleteAsync(taskId, "_update_by_query", index, null, ct);
190+
var taskId = await PostAsyncTaskAsync(url, query, $"POST {index}/_update_by_query", ct)
191+
?? throw new InvalidOperationException($"Failed to start _update_by_query on {index}");
192+
await PollTaskUntilCompleteAsync(taskId, "_update_by_query", index, null, ct);
193193
}
194194
}

0 commit comments

Comments
 (0)