Skip to content

Commit 1186a09

Browse files
authored
Add error and failure info to query result (#22)
Closes #21
1 parent 3d94f54 commit 1186a09

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ export type Columns = {name: string; type: string}[];
9797

9898
export type QueryData = any[];
9999

100+
export type QueryFailureInfo = {
101+
type: string;
102+
message: string;
103+
suppressed: string[];
104+
stack: string[];
105+
};
106+
107+
export type QueryError = {
108+
message: string;
109+
errorCode: number;
110+
errorName: string;
111+
errorType: string;
112+
failureInfo: QueryFailureInfo;
113+
};
114+
100115
export type QueryResult = {
101116
id: string;
102117
infoUri?: string;
@@ -105,12 +120,14 @@ export type QueryResult = {
105120
data?: QueryData[];
106121
stats?: QueryStats;
107122
warnings?: string[];
123+
error?: QueryError;
108124
};
109125

110126
export type QueryInfo = {
111127
queryId: string;
112128
state: string;
113129
query: string;
130+
failureInfo?: QueryFailureInfo;
114131
};
115132

116133
export type Query = {

tests/it/client.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,38 @@ describe('trino', () => {
8080
expect(info.state).toBe('FINISHED');
8181
expect(info.query).toBe(singleCustomerQuery);
8282
});
83+
84+
test.concurrent('QueryResult has error info', async () => {
85+
const trino = new Trino({
86+
catalog: 'tpcds',
87+
schema: 'sf100000',
88+
auth: new BasicAuth('test'),
89+
});
90+
const sqr = await trino.query('select * from foobar where id = -1');
91+
const qr = await sqr.next();
92+
expect(qr.error).toBeDefined();
93+
expect(qr.error?.message).toBe(
94+
"line 1:15: Table 'tpcds.sf100000.foobar' does not exist"
95+
);
96+
97+
await sqr.close();
98+
});
99+
100+
test.concurrent('QueryInfo has failure info', async () => {
101+
const trino = new Trino({
102+
catalog: 'tpcds',
103+
schema: 'sf100000',
104+
auth: new BasicAuth('test'),
105+
});
106+
107+
const sqr = await trino.query('select * from foobar where id = -1');
108+
const qr = await sqr.next();
109+
await sqr.close();
110+
111+
const info = await trino.queryInfo(qr.id);
112+
expect(info.state).toBe('FAILED');
113+
expect(info.failureInfo?.message).toBe(
114+
"line 1:15: Table 'tpcds.sf100000.foobar' does not exist"
115+
);
116+
});
83117
});

0 commit comments

Comments
 (0)