Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/client-search/src/methods/index/replaceAllObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RequestOptions } from '@algolia/transporter';
import {
ChunkedBatchResponse,
ChunkOptions,
deleteIndex,
IndexOperationResponse,
ReplaceAllObjectsOptions,
saveObjects,
Expand Down Expand Up @@ -100,6 +101,15 @@ export const replaceAllObjects = (base: SearchIndex) => {
objectIDs: saveObjectsResponse.objectIDs,
taskIDs: [copyResponse.taskID, ...saveObjectsResponse.taskIDs, moveResponse.taskID],
};
})
.catch(error => {
deleteIndex({
appId: base.appId,
transporter: base.transporter,
indexName: temporaryIndexName,
})();
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteIndex cleanup operation silently swallows any errors. If deletion fails, there's no indication to the caller. Consider logging the deletion failure or adding a comment explaining why errors are intentionally ignored during cleanup.

Suggested change
deleteIndex({
appId: base.appId,
transporter: base.transporter,
indexName: temporaryIndexName,
})();
// Attempt to clean up the temporary index. Log any errors during deletion.
deleteIndex({
appId: base.appId,
transporter: base.transporter,
indexName: temporaryIndexName,
})().catch(deleteError => {
console.error('Failed to delete temporary index during cleanup:', deleteError);
});

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed


throw error;
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary index deletion is not awaited before re-throwing the error. This creates a race condition where the deletion may not complete. Consider using await deleteIndex(...)() to ensure cleanup completes before propagating the error.

Copilot uses AI. Check for mistakes.
});

return createWaitablePromise(result, (_, waitRequestOptions) => {
Expand Down