Skip to content

Commit

Permalink
add sentry logging to all necessary functions
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Khare <[email protected]>
  • Loading branch information
khareyash05 committed Sep 9, 2024
1 parent a92cedb commit dffc7fe
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 218 deletions.
142 changes: 78 additions & 64 deletions src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
import * as vscode from 'vscode';
import { existsSync, readFileSync } from 'fs';
import { SentryInstance } from './sentryInit';

export async function handleOpenKeployConfigFile(webview: any) {
const folderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
const configFilePath = folderPath + '/keploy.yml';

// Function to check if the config file exists
const checkConfigExists = () => {
return existsSync(configFilePath);
};

// Function to open the config file in the editor
const openConfigFile = () => {
vscode.workspace.openTextDocument(configFilePath).then(doc => {
vscode.window.showTextDocument(doc, { preview: false });
});
};

// Check if the config file exists
if (checkConfigExists()) {
openConfigFile();
return;
}

// Create a terminal and execute 'keploy config --generate'
const terminal = vscode.window.createTerminal('Keploy Config Generator');
terminal.sendText('keploy config --generate; exit 0');
terminal.show();

// Polling function to check if the config file is created
const checkFileExists = () => {
return new Promise<boolean>((resolve) => {
const interval = setInterval(() => {
if (checkConfigExists()) {
clearInterval(interval);
resolve(true);
}
}, 2000); // Check every 2 seconds
});
};

// Wait for the config file to be created
const fileExists = await checkFileExists();

if (!fileExists) {
// webview.postMessage({ type: '', value: 'KeployHome' });

webview.postMessage({ type: 'configNotFound', value: 'Config file could not be generated.' });
try {
const folderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
const configFilePath = folderPath + '/keploy.yml';

// Function to check if the config file exists
const checkConfigExists = () => {
return existsSync(configFilePath);
};

// Function to open the config file in the editor
const openConfigFile = () => {
vscode.workspace.openTextDocument(configFilePath).then(doc => {
vscode.window.showTextDocument(doc, { preview: false });
});
};

// Check if the config file exists
if (checkConfigExists()) {
openConfigFile();
return;
}

// Create a terminal and execute 'keploy config --generate'
const terminal = vscode.window.createTerminal('Keploy Config Generator');
terminal.sendText('keploy config --generate; exit 0');
terminal.show();

// Polling function to check if the config file is created
const checkFileExists = () => {
return new Promise<boolean>((resolve) => {
const interval = setInterval(() => {
if (checkConfigExists()) {
clearInterval(interval);
resolve(true);
}
}, 2000); // Check every 2 seconds
});
};

// Wait for the config file to be created
const fileExists = await checkFileExists();

if (!fileExists) {
webview.postMessage({ type: 'configNotFound', value: 'Config file could not be generated.' });
}

} catch (error) {
// Log the error to Sentry
SentryInstance?.captureException(error);
vscode.window.showErrorMessage('An error occurred while handling the Keploy config file.');
}
}

export async function handleInitializeKeployConfigFile(webview: any, path: string, command: string) {
console.log('Initializing config file');
try {
console.log('Initializing config file');

const folderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
const configFilePath = `${folderPath}/keploy.yml`;
const folderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
const configFilePath = `${folderPath}/keploy.yml`;

if (path === '') {
path = "./";
}
if (path === '') {
path = "./";
}

// Initialize the config file with the provided path and command
const initContent = `
// Initialize the config file with the provided path and command
const initContent = `
path: "${path}"
appId: ""
command: "${command}"
Expand Down Expand Up @@ -98,20 +105,27 @@ enableTesting: false
fallbackOnMiss: false
# This config file has been initialized
`;
`;

const finalContent = `${initContent.trim()}
const finalContent = `${initContent.trim()}
# Visit https://keploy.io/docs/running-keploy/configuration-file/ to learn about using Keploy through the configuration file.
`;
`;

// Write the content to the config file
await vscode.workspace.fs.writeFile(vscode.Uri.file(configFilePath), Buffer.from(finalContent));
// Write the content to the config file
await vscode.workspace.fs.writeFile(vscode.Uri.file(configFilePath), Buffer.from(finalContent));

// Open the config file in the editor
vscode.workspace.openTextDocument(configFilePath).then(doc => {
vscode.window.showTextDocument(doc, { preview: false });
});
console.log('finalContent', finalContent);
webview.postMessage({ type: 'navigateToHome', value: 'KeployHome' });
// Open the config file in the editor
vscode.workspace.openTextDocument(configFilePath).then(doc => {
vscode.window.showTextDocument(doc, { preview: false });
});

console.log('finalContent', finalContent);
webview.postMessage({ type: 'navigateToHome', value: 'KeployHome' });

} catch (error) {
// Log the error to SentryInstance
SentryInstance?.captureException(error);
vscode.window.showErrorMessage('An error occurred while initializing the Keploy config file.');
}
}
3 changes: 3 additions & 0 deletions src/OneClickInstall.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { exec } from 'child_process';
import { SentryInstance } from './sentryInit';

export default function executeKeployOneClickCommand(): void {
// check before if keploy has been installed first
Expand All @@ -9,11 +10,13 @@ export default function executeKeployOneClickCommand(): void {
if (error) {
exec(installationCommand, (error, stdout, stderr) => {
if (error) {
SentryInstance?.captureException(error);
console.error(`Error executing command: ${error.message}`);
return;
}

if (stderr) {
SentryInstance?.captureException(new Error(stderr));
console.error(`Command execution returned an error: ${stderr}`);
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { readFileSync , appendFile} from 'fs';
import * as child_process from 'child_process';
import * as os from 'os';
import { SentryInstance } from './sentryInit';

function extractTestSetName(logContent: string) {
// Define the regular expression pattern to find the test set name
Expand Down Expand Up @@ -62,6 +63,7 @@ export async function displayRecordedTestCases(logfilePath: string, webview: any
textContent: error,
error: true
});
SentryInstance?.captureException(error);
vscode.window.showErrorMessage('Error occurred Keploy Record: ' + error);
throw error;
}
Expand All @@ -78,6 +80,7 @@ export async function stopRecording(){
return;
}
catch(error){
SentryInstance?.captureException(error);
console.log(error);
throw error;
}
Expand Down Expand Up @@ -142,12 +145,14 @@ export async function startRecording( wslscriptPath: string, wsllogfilePath: str

} catch (error) {
console.log(error);
SentryInstance?.captureException(error);
vscode.window.showErrorMessage('Error occurred Keploy Record: ' + error);
reject(error);
}
});
} catch (error) {
console.log(error);
SentryInstance?.captureException(error);
vscode.window.showErrorMessage('Error occurred Keploy Record: ' + error);
throw error;
}
Expand Down
Loading

0 comments on commit dffc7fe

Please sign in to comment.