Skip to content

Commit 6e72d92

Browse files
fix(redshift): misleading error for queries with no results
1 parent 2cc8970 commit 6e72d92

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/redshift/notebook/redshiftNotebookController.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import * as vscode from 'vscode'
8-
import { DefaultRedshiftClient, ExecuteQueryResponse } from '../../shared/clients/redshiftClient'
8+
import { DefaultRedshiftClient } from '../../shared/clients/redshiftClient'
99
import { ConnectionParams } from '../models/models'
1010
import { RedshiftData } from 'aws-sdk'
1111
import { telemetry } from '../../shared/telemetry/telemetry'
@@ -84,16 +84,22 @@ export class RedshiftNotebookController {
8484
let nextToken: string | undefined
8585
// get all the pages of the result
8686
do {
87-
const result: ExecuteQueryResponse = await this.redshiftClient!.executeQuery(
87+
const result = await this.redshiftClient!.executeQuery(
8888
connectionParams,
8989
cell.document.getText(),
9090
nextToken,
9191
executionId
9292
)
93-
nextToken = result.statementResultResponse.NextToken
94-
executionId = result.executionId
95-
columnMetadata = result.statementResultResponse.ColumnMetadata
96-
records.push(...result.statementResultResponse.Records)
93+
if (result) {
94+
nextToken = result.statementResultResponse.NextToken
95+
executionId = result.executionId
96+
columnMetadata = result.statementResultResponse.ColumnMetadata
97+
records.push(...result.statementResultResponse.Records)
98+
} else {
99+
return new vscode.NotebookCellOutput([
100+
vscode.NotebookCellOutputItem.text('No records.', 'text/plain'),
101+
])
102+
}
97103
} while (nextToken)
98104

99105
if (columnMetadata) {

src/shared/clients/redshiftClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class DefaultRedshiftClient {
149149
queryToExecute: string,
150150
nextToken?: string,
151151
executionId?: string
152-
): Promise<ExecuteQueryResponse> {
152+
): Promise<ExecuteQueryResponse | undefined> {
153153
const redshiftData = await this.redshiftDataClientProvider(this.regionCode)
154154
// if executionId is not passed in, that means that we're executing and retrieving the results of the query for the first time.
155155
if (!executionId) {
@@ -189,6 +189,8 @@ export class DefaultRedshiftClient {
189189
throw new Error(
190190
`Failed to run query: '${queryToExecute}': '${describeStatementResponse.Error}'`
191191
)
192+
} else if (status === 'FINISHED') {
193+
return undefined
192194
}
193195
break
194196
} else {

0 commit comments

Comments
 (0)