Skip to content

Commit

Permalink
Validate results gotten from sema4ai-data.dataserver.start.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 11, 2024
1 parent 4a236d8 commit 6067624
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
69 changes: 68 additions & 1 deletion sema4ai/vscode-client/src/dataExtension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { commands, extensions, window } from "vscode";
import { logError } from "./channel";
import { logError, OUTPUT_CHANNEL } from "./channel";
import { DataServerConfig } from "./robo/actionPackage";

const DATA_EXTENSION_ID = "sema4ai.sema4ai-data-access";
export const DATA_SERVER_START_COMMAND_ID = "sema4ai-data.dataserver.start";
Expand Down Expand Up @@ -85,3 +86,69 @@ export async function verifyDataExtensionIsInstalled(

return false;
}

function failWithErrorMessage(dataServerInfo: DataServerConfig, errorMessage: string) {
OUTPUT_CHANNEL.appendLine(
`${errorMessage} (obtained from the ${DATA_SERVER_START_COMMAND_ID} command). Full data server info: ` +
JSON.stringify(dataServerInfo, null, 4)
);
window.showErrorMessage(errorMessage);
}

export async function startDataServerAndGetInfo(): Promise<DataServerConfig | undefined> {
const dataServerInfo = (await commands.executeCommand(DATA_SERVER_START_COMMAND_ID, {
"showUIMessages": false,
})) as DataServerConfig | undefined;
if (dataServerInfo) {
if (!dataServerInfo.isRunning) {
failWithErrorMessage(
dataServerInfo,
"After starting the data server, isRunning still returning false in provided data server config."
);
return undefined;
}

// Let's validate that the data server info has the correct structure (check each field one by one and
// show error if it's not correct)
if (!dataServerInfo.api) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api' field");
return undefined;
}

if (!dataServerInfo.api.http) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.http' field");
return undefined;
}

if (!dataServerInfo.api.http.host) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.http.host' field");
return undefined;
}

if (!dataServerInfo.api.http.port) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.http.port' field");
return undefined;
}

if (!dataServerInfo.api.mysql) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.mysql' field");
return undefined;
}

if (!dataServerInfo.api.mysql.host) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.mysql.host' field");
return undefined;
}

if (!dataServerInfo.api.mysql.port) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'api.mysql.port' field");
return undefined;
}

if (!dataServerInfo.auth) {
failWithErrorMessage(dataServerInfo, "The data server info is missing the 'auth' field");
return undefined;
}
}
return dataServerInfo;
}
12 changes: 3 additions & 9 deletions sema4ai/vscode-client/src/robo/actionPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ import { loginToAuth2WhereRequired } from "./oauth2InInput";
import { RobotEntryType } from "../viewsCommon";
import { createActionInputs, errorMessageValidatingV2Input } from "./actionInputs";
import { langServer } from "../extension";
import {
DATA_SERVER_START_COMMAND_ID,
DATA_SERVER_STATUS_COMMAND_ID,
verifyDataExtensionIsInstalled,
} from "../dataExtension";
import { startDataServerAndGetInfo, verifyDataExtensionIsInstalled } from "../dataExtension";

export interface QuickPickItemAction extends QuickPickItem {
actionPackageUri: vscode.Uri;
Expand Down Expand Up @@ -574,12 +570,10 @@ advised to regenerate it as it may not work with future versions of the extensio
progress.report({
message: "Waiting for data server info... ",
});
const dataServerInfo = (await commands.executeCommand(DATA_SERVER_START_COMMAND_ID, {
"showUIMessages": false,
})) as DataServerConfig | undefined;
const dataServerInfo = await startDataServerAndGetInfo();
if (!dataServerInfo) {
window.showErrorMessage(
"Unable to run (error getting local data server connection info and validating data sources):\n" +
"Unable to run (error getting local data server connection info):\n" +
JSON.stringify(dataServerInfo, null, 4)
);
return false;
Expand Down
11 changes: 4 additions & 7 deletions sema4ai/vscode-client/src/robo/dataSourceHandling.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { commands, Uri, window } from "vscode";
import { Uri, window } from "vscode";
import { OUTPUT_CHANNEL } from "../channel";
import { RobotEntry } from "../viewsCommon";
import { DatasourceInfo } from "../protocols";
import { langServer } from "../extension";
import { DataServerConfig } from "./actionPackage";
import { DATA_SERVER_START_COMMAND_ID } from "../dataExtension";
import { startDataServerAndGetInfo } from "../dataExtension";

export const setupDataSource = async (entry?: RobotEntry) => {
if (!entry || !entry.extraData || !entry.extraData.datasource) {
window.showErrorMessage("Data source not specified.");
return;
}

const dataServerInfo = (await commands.executeCommand(DATA_SERVER_START_COMMAND_ID, {
"showUIMessages": false,
})) as DataServerConfig | undefined;
const dataServerInfo = await startDataServerAndGetInfo();
if (!dataServerInfo) {
window.showErrorMessage(
"Unable to run (error getting local data server connection info and validating data sources):\n" +
"Unable to run (error getting local data server connection info):\n" +
JSON.stringify(dataServerInfo, null, 4)
);
return false;
Expand Down

0 comments on commit 6067624

Please sign in to comment.