fix(node): contain rejected table write progress callbacks (#5274)

Fixes #5273

## Summary

Handle promises returned from `Table.add(..., { progress })` through the
existing callback warning path. The callback stays unawaited and the
write does not depend on its result. The patch covers write progress in
the native append path, which is separate from `Job.wait` progress.

## Validation

- The real native append regression resolves the write, reads its newly
committed rows, and then rejects the final progress callback. All seven
Apache Arrow variant cases fail on main because the warning is missing.
- With the patch, 28 append, overwrite, and progress tests pass with the
matching native beta binding.
- An actual Node run with `--unhandled-rejections=strict` exits on the
observer error on main. The patch logs the warning and reads three
expected rows.
- Biome checks on changed files and `git diff --check` pass.

---------

Co-authored-by: Divyam Talwar <237515611+DivyamTalwar@users.noreply.github.com>
Co-authored-by: Divyam Talwar <DivyamTalwar@users.noreply.github.com>
This commit is contained in:
Divyam Talwar
2026-11-30 21:46:22 +08:00
committed by GitHub
co-authored by Divyam Talwar Divyam Talwar
parent c90382e9c4
commit c105797249
3 changed files with 49 additions and 6 deletions
+3 -2
View File
@@ -51,8 +51,9 @@ The callback is fired once per batch written and once more with
asynchronously to the JS event loop and never block the write — a slow
callback will queue events rather than back-pressure the writer.
Errors thrown from the callback are logged with `console.warn` and
swallowed — they do not abort the write.
If a callback throws or returns a rejected promise, the error is logged
with `console.warn`. The write neither awaits the callback nor fails
because of it.
#### Parameters
+35
View File
@@ -393,6 +393,41 @@ describe.each(arrowVersions)(
}
});
it("reports rejected progress promises without interrupting a completed append", async () => {
const error = new Error("write observer failed");
let reject!: (reason: Error) => void;
const pending = new Promise<void>((_resolve, rejectPromise) => {
reject = rejectPromise;
});
// Prevent Jest from treating the baseline's escaped rejection as
// a harness error. The missing warning is the regression assertion.
pending.catch(() => undefined);
const progress = jest.fn(
(snapshot: import("../lancedb").WriteProgress) =>
snapshot.done ? pending : undefined,
);
const warn = jest
.spyOn(console, "warn")
.mockImplementation(() => undefined);
try {
const initialCount = await table.countRows();
const result = await table.add([{ id: 1 }, { id: 2 }], { progress });
expect(result.version).toBeGreaterThan(0);
expect(progress).toHaveBeenCalledWith(
expect.objectContaining({ done: true }),
);
expect(await table.countRows()).toBe(initialCount + 2);
reject(error);
await new Promise<void>((resolve) => setImmediate(resolve));
expect(warn).toHaveBeenCalledWith(
"Table.add progress callback threw:",
error,
);
} finally {
warn.mockRestore();
}
});
it("should let me close the table", async () => {
expect(table.isOpen()).toBe(true);
table.close();
+11 -4
View File
@@ -197,8 +197,9 @@ export interface AddDataOptions {
* asynchronously to the JS event loop and never block the write — a slow
* callback will queue events rather than back-pressure the writer.
*
* Errors thrown from the callback are logged with `console.warn` and
* swallowed — they do not abort the write.
* If a callback throws or returns a rejected promise, the error is logged
* with `console.warn`. The write neither awaits the callback nor fails
* because of it.
*
* @example
* ```ts
@@ -1809,12 +1810,18 @@ export class LocalTable extends Table {
// unhandled exception (the callback fires from a napi threadsafe
// function — exceptions there crash the process).
const userProgress = options?.progress;
const reportProgressError = (error: unknown) => {
console.warn("Table.add progress callback threw:", error);
};
const progress = userProgress
? (p: WriteProgress) => {
try {
userProgress(p);
const result = userProgress(p);
if (result !== undefined) {
void Promise.resolve(result).catch(reportProgressError);
}
} catch (e) {
console.warn("Table.add progress callback threw:", e);
reportProgressError(e);
}
}
: undefined;