diff --git a/README.md b/README.md index 9e41bb0e..3b0f6011 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,6 @@ To add connections: - [My q](#my-q): This is an unmanaged q session and is a connection to a remote q process. - [Insights](#insights-connection): This accesses **kdb Insights Enterprise** API endpoints and a user-specific scratchpad process within a **kdb Insights Enterprise** deployment. - ![setendpoint](https://github.com/KxSystems/kx-vscode/blob/main/img/bundleqform.png?raw=true) - 1. Set the properties appropriate to the connection type as described in the following sections. ### Bundled q @@ -143,6 +141,8 @@ When you select **Bundled q** as the connection type and set the following prope | Port | Set the port for the kdb server. Ensure the port used doesn't conflict with any other running q process; e.g. 5002. [Read here for more about setting a q port](https://code.kx.com/q/basics/ipc/) | | Label Name | Select the label you want to assign the connection to | +![setendpoint](https://github.com/KxSystems/kx-vscode/blob/main/img/bundleq.png?raw=true) + 1. Click **Create Connection** and the connection appears under **CONNECTIONS** in the primary sidebar.. 1. Right-click the q bundled process listed under **CONNECTIONS**, and click **Start q process**. diff --git a/img/bundleq.png b/img/bundleq.png new file mode 100644 index 00000000..bb0f9ccc Binary files /dev/null and b/img/bundleq.png differ diff --git a/img/bundleqform.png b/img/bundleqform.png deleted file mode 100644 index 3ae065e1..00000000 Binary files a/img/bundleqform.png and /dev/null differ diff --git a/img/conn-labels-tree.png b/img/conn-labels-tree.png index 4d2d0b4c..6c7e3f2c 100644 Binary files a/img/conn-labels-tree.png and b/img/conn-labels-tree.png differ diff --git a/img/conn-labels.png b/img/conn-labels.png index 1a354126..b3e0bbe1 100644 Binary files a/img/conn-labels.png and b/img/conn-labels.png differ diff --git a/img/create-new-label-btn.png b/img/create-new-label-btn.png index 7495c1ad..00d2b619 100644 Binary files a/img/create-new-label-btn.png and b/img/create-new-label-btn.png differ diff --git a/img/edit-bundle-q-conn-form.png b/img/edit-bundle-q-conn-form.png index e1d72764..e853e23f 100644 Binary files a/img/edit-bundle-q-conn-form.png and b/img/edit-bundle-q-conn-form.png differ diff --git a/img/edit-insights-conn-form.png b/img/edit-insights-conn-form.png index 5459d350..3bda0433 100644 Binary files a/img/edit-insights-conn-form.png and b/img/edit-insights-conn-form.png differ diff --git a/img/edit-my-q-conn-form.png b/img/edit-my-q-conn-form.png index 1beb2ec4..154cacfc 100644 Binary files a/img/edit-my-q-conn-form.png and b/img/edit-my-q-conn-form.png differ diff --git a/img/insightsconnection.png b/img/insightsconnection.png index 51fdb310..37e3b050 100644 Binary files a/img/insightsconnection.png and b/img/insightsconnection.png differ diff --git a/img/myq.png b/img/myq.png index ec59e907..29d5e5fc 100644 Binary files a/img/myq.png and b/img/myq.png differ diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index c8cfad57..f740b528 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -464,10 +464,7 @@ export class InsightsConnection { }) .then((response: any) => { if (response.data.error) { - kdbOutputLog( - `[SCRATCHPAD] Error occured while executing scratchpad: ${response.data.errorMsg}`, - "ERROR", - ); + return response.data; } else if (query === "") { kdbOutputLog( `[SCRATCHPAD] scratchpad created for connection: ${this.connLabel}`, diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index 34643893..d63b7edc 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -164,11 +164,14 @@ export async function runDataSource( if (!success) { window.showErrorMessage(res.error); - } else if (ext.isResultsTabVisible) { - const resultCount = typeof res === "string" ? "0" : res.rows.length; - kdbOutputLog(`[DATASOURCE] Results: ${resultCount} rows`, "INFO"); + } + if (ext.isResultsTabVisible) { + if (success) { + const resultCount = typeof res === "string" ? "0" : res.rows.length; + kdbOutputLog(`[DATASOURCE] Results: ${resultCount} rows`, "INFO"); + } writeQueryResultsToView( - res, + success ? res : res.error, query, connLabel, executorName, @@ -176,12 +179,14 @@ export async function runDataSource( selectedType, ); } else { - kdbOutputLog( - `[DATASOURCE] Results is a string with length: ${res.length}`, - "INFO", - ); + if (success) { + kdbOutputLog( + `[DATASOURCE] Results is a string with length: ${res.length}`, + "INFO", + ); + } writeQueryResultsToConsole( - res, + success ? res : res.error, query, connLabel, executorName, @@ -415,7 +420,11 @@ export function parseError(error: GetDataError) { if (error instanceof Object && error.buffer) { return handleWSError(error.buffer); } else { - kdbOutputLog(`[DATASOURCE] Error: ${error}`, "ERROR"); + kdbOutputLog( + `[DATASOURCE] Error: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`, + "ERROR", + true, + ); return { error, }; diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 2222f756..ce3d854f 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -1184,47 +1184,30 @@ export function writeScratchpadResult( duration: string, connVersion: number, ): void { - const queryConsole = ExecutionConsole.start(); - - if (result.error) { - queryConsole.appendQueryError( + if (ext.isResultsTabVisible) { + writeQueryResultsToView( + result.error ? result.errorMsg : result, query, - result.errorMsg, connLabel, executorName, true, - true, isWorkbook ? "WORKBOOK" : "SCRATCHPAD", isPython, - false, duration, + false, + connVersion, ); } else { - if (ext.isResultsTabVisible) { - writeQueryResultsToView( - result, - query, - connLabel, - executorName, - true, - isWorkbook ? "WORKBOOK" : "SCRATCHPAD", - isPython, - duration, - false, - connVersion, - ); - } else { - writeQueryResultsToConsole( - result.data, - query, - connLabel, - executorName, - true, - isWorkbook ? "WORKBOOK" : "SCRATCHPAD", - isPython, - duration, - ); - } + writeQueryResultsToConsole( + result.error ? result.errorMsg : result.data, + query, + connLabel, + executorName, + true, + isWorkbook ? "WORKBOOK" : "SCRATCHPAD", + isPython, + duration, + ); } } diff --git a/src/utils/core.ts b/src/utils/core.ts index 1c3c641e..4ccebd18 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -313,11 +313,15 @@ export function getServerAlias(serverList: ServerDetails[]): void { }); } -export function kdbOutputLog(message: string, type: string): void { +export function kdbOutputLog( + message: string, + type: string, + supressDialog?: boolean, +): void { const dateNow = new Date().toLocaleDateString(); const timeNow = new Date().toLocaleTimeString(); ext.outputChannel.appendLine(`[${dateNow} ${timeNow}] [${type}] ${message}`); - if (type === "ERROR") { + if (type === "ERROR" && !supressDialog) { window.showErrorMessage( `Error occured, check kdb output channel for details.`, ); diff --git a/src/utils/queryUtils.ts b/src/utils/queryUtils.ts index a92d4fd4..f50dee9a 100644 --- a/src/utils/queryUtils.ts +++ b/src/utils/queryUtils.ts @@ -91,7 +91,7 @@ export function handleWSError(ab: ArrayBuffer): any { } } - kdbOutputLog(`Error : ${errorString}`, "ERROR"); + kdbOutputLog(`Error : ${errorString}`, "ERROR", true); return { error: errorString }; } diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index 5c6324c6..f3865626 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -604,6 +604,9 @@ describe("dataSourceCommand2", () => { }, insightsNode: "dummyNode", }; + const dummyError = { + error: "error message", + }; const connMngService = new ConnectionManagementService(); const uriTest: vscode.Uri = vscode.Uri.parse("test"); const ab = new ArrayBuffer(26); @@ -678,6 +681,44 @@ describe("dataSourceCommand2", () => { .withArgs("No Insights active connection found"); }); + it("should return error for visible results panel", async () => { + ext.connectedConnectionList.push(insightsConn); + retrieveConnStub.resolves(insightsConn); + insightsConn.meta = dummyMeta; + getMetaStub.resolves(dummyMeta); + sinon.stub(dataSourceCommand, "runQsqlDataSource").resolves(dummyError); + + ext.isResultsTabVisible = true; + await dataSourceCommand.runDataSource( + dummyFileContent as DataSourceFiles, + insightsConn.connLabel, + "test-file.kdb.json", + ); + sinon.assert.neverCalledWith(writeQueryResultsToConsoleStub); + sinon.assert.calledOnce(writeQueryResultsToViewStub); + + ext.connectedConnectionList.length = 0; + }); + + it("should return error for console panel", async () => { + ext.connectedConnectionList.push(insightsConn); + retrieveConnStub.resolves(insightsConn); + insightsConn.meta = dummyMeta; + getMetaStub.resolves(dummyMeta); + sinon.stub(dataSourceCommand, "runQsqlDataSource").resolves(dummyError); + + ext.isResultsTabVisible = false; + await dataSourceCommand.runDataSource( + dummyFileContent as DataSourceFiles, + insightsConn.connLabel, + "test-file.kdb.json", + ); + sinon.assert.neverCalledWith(writeQueryResultsToViewStub); + sinon.assert.calledOnce(writeQueryResultsToConsoleStub); + + ext.connectedConnectionList.length = 0; + }); + it("should return QSQL results", async () => { ext.connectedConnectionList.push(insightsConn); retrieveConnStub.resolves(insightsConn); @@ -894,9 +935,6 @@ describe("dataSourceCommand2", () => { const result = dataSourceCommand.parseError(error); assert(kdbOutputLogStub.calledOnce); - assert( - kdbOutputLogStub.calledWith(`[DATASOURCE] Error: ${error}`, "ERROR"), - ); assert.deepEqual(result, { error }); }); });