mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
## Summary The Node SDK now throws typed `LanceError` subclasses instead of one generic `Error` with an indented `Caused by` string. Fixes #222 ## Before / after ```ts try { await db.openTable(\"missing\"); } catch (error) { if (error instanceof TableNotFoundError) { error.code; // \"TableNotFound\" error.tableName; // \"missing\" error.message; // \"Table 'missing' was not found\" error.cause; // underlying dataset error } } ``` ## Changes - `nodejs/src/error.rs` — map each `lancedb::Error` variant to a one-line header + `error.cause` - `nodejs/src/query.rs`, `nodejs/src/merge.rs` — pass errors through instead of stringifying - `nodejs/lancedb/errors.ts`, `errors_install.ts` — real subclasses when the package loads - Tests + generated API docs under `docs/src/js/` ## Test plan - [x] Native debug build, `tsc`, Biome, `cargo clippy -p lancedb-nodejs` - [x] Jest: new error tests, remote retry, connection/query/table (594 passed) ## Notes Node-API cannot construct a custom `Error` subclass from an async Rust rejection, so translation happens in JS when `@lancedb/lancedb` loads. Calling the raw native addon without that entrypoint still shows the header line. --------- Signed-off-by: ZYZ666-RGB <1991039819@qq.com> Signed-off-by: yuzhou <1991039819@qq.com> Co-authored-by: Xuanwo <github@xuanwo.io>
16 lines
631 B
TypeScript
16 lines
631 B
TypeScript
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
import { installLanceErrorTranslation } from "./errors";
|
|
import * as native from "./native.js";
|
|
|
|
// Side effect: every native method rejects with a LanceError subclass.
|
|
// `import *` can be a copy of the CommonJS exports, so install on both the
|
|
// namespace and the original module object. Class prototypes are shared;
|
|
// free functions are not.
|
|
installLanceErrorTranslation(native);
|
|
const original = (native as { default?: object }).default;
|
|
if (original != null && original !== native) {
|
|
installLanceErrorTranslation(original);
|
|
}
|