Skip to content

Commit

Permalink
Merge pull request #476 from KxSystems/KXI-57634
Browse files Browse the repository at this point in the history
KXI-57634 - Error not showing where supposed to be
  • Loading branch information
Philip-Carneiro-KX authored Dec 13, 2024
2 parents 56b05e4 + 90b1f09 commit 3699b56
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**.
Expand Down
Binary file added img/bundleq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/bundleqform.png
Binary file not shown.
Binary file modified img/conn-labels-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/conn-labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/create-new-label-btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/edit-bundle-q-conn-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/edit-insights-conn-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/edit-my-q-conn-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/insightsconnection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/myq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/classes/insightsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
29 changes: 19 additions & 10 deletions src/commands/dataSourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,29 @@ 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,
true,
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,
Expand Down Expand Up @@ -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,
};
Expand Down
47 changes: 15 additions & 32 deletions src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function handleWSError(ab: ArrayBuffer): any {
}
}

kdbOutputLog(`Error : ${errorString}`, "ERROR");
kdbOutputLog(`Error : ${errorString}`, "ERROR", true);

return { error: errorString };
}
Expand Down
44 changes: 41 additions & 3 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
});
});
Expand Down

0 comments on commit 3699b56

Please sign in to comment.