From 20ab85171b6e5f9f17679d140bf44e0191c30e9e Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 3 Nov 2023 10:24:56 -0400 Subject: [PATCH] fix: node remote connection handles non http errors (#624) https://github.com/lancedb/lancedb/issues/623 Fixes issue trying to print response status when using remote client. If the error is not an HTTP error (e.g. dns/network failure), there won't be a response. --- node/src/remote/client.ts | 9 +++++++++ node/src/test/test.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 5911cd48..6d3cd934 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -63,6 +63,9 @@ export class HttpLancedbClient { } ).catch((err) => { console.error('error: ', err) + if (err.response === undefined) { + throw new Error(`Network Error: ${err.message as string}`) + } return err.response }) if (response.status !== 200) { @@ -93,6 +96,9 @@ export class HttpLancedbClient { } ).catch((err) => { console.error('error: ', err) + if (err.response === undefined) { + throw new Error(`Network Error: ${err.message as string}`) + } return err.response }) if (response.status !== 200) { @@ -128,6 +134,9 @@ export class HttpLancedbClient { } ).catch((err) => { console.error('error: ', err) + if (err.response === undefined) { + throw new Error(`Network Error: ${err.message as string}`) + } return err.response }) if (response.status !== 200) { diff --git a/node/src/test/test.ts b/node/src/test/test.ts index 777a250f..7cb6d52c 100644 --- a/node/src/test/test.ts +++ b/node/src/test/test.ts @@ -396,6 +396,40 @@ describe('LanceDB client', function () { }) }) +describe('Remote LanceDB client', function () { + describe('when the server is not reachable', function () { + it('produces a network error', async function () { + const con = await lancedb.connect({ + uri: 'db://test-1234', + region: 'asdfasfasfdf', + apiKey: 'some-api-key' + }) + + // GET + try { + await con.tableNames() + } catch (err) { + expect(err).to.have.property('message', 'Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com') + } + + // POST + try { + await con.createTable({ name: 'vectors', schema: new Schema([]) }) + } catch (err) { + expect(err).to.have.property('message', 'Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com') + } + + // Search + const table = await con.openTable('vectors') + try { + await table.search([0.1, 0.3]).execute() + } catch (err) { + expect(err).to.have.property('message', 'Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com') + } + }) + }) +}) + describe('Query object', function () { it('sets custom parameters', async function () { const query = new Query([0.1, 0.3])