Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

[FR] Improve the BulkWriter API to prevent UnhandledRejections #1282

@sk-

Description

@sk-

The BulkWriter class was made public in version 4.1.0. however, it has some use disadvantages compared to using a BatchWriter.

The problem lies in the fact that close never fails, and the fact that writing (update, delete, set) returns a promise.

This makes it difficult and awkward to correctly handle errors, which is absolutely necessary on cloud functions, as UnhandledRejections will make the whole function to fail with a very cryptic error.

It'd be great if we could write something like:

const writer = db.bulkWriter();
writer.update(ref1, {...});
writer.update(ref2, {...});
try {
  await writer.commit();
} catch (error) {
  // decide whether to continue, fail, log or do something else based on the error.
  // error could be an object having a `failures` and `succeses` fields, where each failure or success has the all the arguments of the write operation. 
  // Or something similar to the result of promiseAllSettled. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
}

Note that using WriteBatch resembles the proposed API.

Compare that to what one needs to do today.

let sharedState = ...;
const writer = db.bulkWriter();
 // depending on whether we want to skip failures or actually fail what the catch function will be
writer.update(ref1, {...}).catch(...);
writer.update(ref2, {...}).catch(...);
await writer.close();
// Check shared state

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions