From c1057972490eb2a4e9a5006b3be5fc5aa8138ef0 Mon Sep 17 00:00:00 2001 From: Divyam Talwar Date: Mon, 30 Nov 2026 19:16:22 +0530 Subject: [PATCH] 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 --- docs/src/js/interfaces/AddDataOptions.md | 5 ++-- nodejs/__test__/table.test.ts | 35 ++++++++++++++++++++++++ nodejs/lancedb/table.ts | 15 +++++++--- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/docs/src/js/interfaces/AddDataOptions.md b/docs/src/js/interfaces/AddDataOptions.md index 567269471..c69e4ad20 100644 --- a/docs/src/js/interfaces/AddDataOptions.md +++ b/docs/src/js/interfaces/AddDataOptions.md @@ -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 diff --git a/nodejs/__test__/table.test.ts b/nodejs/__test__/table.test.ts index e712b59e7..74ebdd853 100644 --- a/nodejs/__test__/table.test.ts +++ b/nodejs/__test__/table.test.ts @@ -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((_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((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(); diff --git a/nodejs/lancedb/table.ts b/nodejs/lancedb/table.ts index 5dc1c445e..7b6fe4efc 100644 --- a/nodejs/lancedb/table.ts +++ b/nodejs/lancedb/table.ts @@ -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;