From 1186a09077b33803fd4cc51a3645e6a2441b2019 Mon Sep 17 00:00:00 2001 From: Filipe Regadas Date: Fri, 8 Jul 2022 09:38:25 +0100 Subject: [PATCH] Add error and failure info to query result (#22) Closes #21 --- src/index.ts | 17 +++++++++++++++++ tests/it/client.spec.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/index.ts b/src/index.ts index 59710e46..a09f8e81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,6 +97,21 @@ export type Columns = {name: string; type: string}[]; export type QueryData = any[]; +export type QueryFailureInfo = { + type: string; + message: string; + suppressed: string[]; + stack: string[]; +}; + +export type QueryError = { + message: string; + errorCode: number; + errorName: string; + errorType: string; + failureInfo: QueryFailureInfo; +}; + export type QueryResult = { id: string; infoUri?: string; @@ -105,12 +120,14 @@ export type QueryResult = { data?: QueryData[]; stats?: QueryStats; warnings?: string[]; + error?: QueryError; }; export type QueryInfo = { queryId: string; state: string; query: string; + failureInfo?: QueryFailureInfo; }; export type Query = { diff --git a/tests/it/client.spec.ts b/tests/it/client.spec.ts index efd1a51c..7e24e607 100644 --- a/tests/it/client.spec.ts +++ b/tests/it/client.spec.ts @@ -80,4 +80,38 @@ describe('trino', () => { expect(info.state).toBe('FINISHED'); expect(info.query).toBe(singleCustomerQuery); }); + + test.concurrent('QueryResult has error info', async () => { + const trino = new Trino({ + catalog: 'tpcds', + schema: 'sf100000', + auth: new BasicAuth('test'), + }); + const sqr = await trino.query('select * from foobar where id = -1'); + const qr = await sqr.next(); + expect(qr.error).toBeDefined(); + expect(qr.error?.message).toBe( + "line 1:15: Table 'tpcds.sf100000.foobar' does not exist" + ); + + await sqr.close(); + }); + + test.concurrent('QueryInfo has failure info', async () => { + const trino = new Trino({ + catalog: 'tpcds', + schema: 'sf100000', + auth: new BasicAuth('test'), + }); + + const sqr = await trino.query('select * from foobar where id = -1'); + const qr = await sqr.next(); + await sqr.close(); + + const info = await trino.queryInfo(qr.id); + expect(info.state).toBe('FAILED'); + expect(info.failureInfo?.message).toBe( + "line 1:15: Table 'tpcds.sf100000.foobar' does not exist" + ); + }); });