From 5661a337958d16dead8b5fcdc4e2485f4a921162 Mon Sep 17 00:00:00 2001 From: Dusan Petrovic Date: Fri, 10 Jan 2025 17:09:59 +0100 Subject: [PATCH] Error handling for TestAdapter and DBConfigurationProvider --- .../vscode/src/dbConfigurationProvider.ts | 11 +++++++-- java/java.lsp.server/vscode/src/extension.ts | 2 +- .../java.lsp.server/vscode/src/testAdapter.ts | 23 ++++++++++++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/java/java.lsp.server/vscode/src/dbConfigurationProvider.ts b/java/java.lsp.server/vscode/src/dbConfigurationProvider.ts index 91a4e6ce0221..c311e62489b4 100644 --- a/java/java.lsp.server/vscode/src/dbConfigurationProvider.ts +++ b/java/java.lsp.server/vscode/src/dbConfigurationProvider.ts @@ -43,8 +43,15 @@ class DBConfigurationProvider implements vscode.DebugConfigurationProvider { } resolveDebugConfigurationWithSubstitutedVariables?(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult { - return new Promise(async resolve => { - let o: Object = await vscode.commands.executeCommand('nbls.db.connection'); + return new Promise(async (resolve, reject) => { + let o: Object; + try { + o = await vscode.commands.executeCommand('nbls.db.connection'); + } catch(err) { + console.log(err); + reject(err); + return; + } if (config === undefined) { config = {} as vscode.DebugConfiguration; } diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts index d43b8dcd16c0..5589d312f509 100644 --- a/java/java.lsp.server/vscode/src/extension.ts +++ b/java/java.lsp.server/vscode/src/extension.ts @@ -939,7 +939,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI { }; context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel', async (projects?) => { - testAdapter?.runTestsWithParallelParallel(projects); + testAdapter?.runTestsWithParallelProfile(projects); })); context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel.createProfile', async (projects?) => { diff --git a/java/java.lsp.server/vscode/src/testAdapter.ts b/java/java.lsp.server/vscode/src/testAdapter.ts index e4d9f3feb34b..e4c133950b4c 100644 --- a/java/java.lsp.server/vscode/src/testAdapter.ts +++ b/java/java.lsp.server/vscode/src/testAdapter.ts @@ -58,7 +58,7 @@ export class NbTestAdapter { return this.parallelRunProfile ? true : false; } - public runTestsWithParallelParallel(projects?: string[]) { + public runTestsWithParallelProfile(projects?: string[]) { if (this.parallelRunProfile) { this.run(new TestRunRequest(undefined, undefined, this.parallelRunProfile), new CancellationTokenSource().token, true, projects); } @@ -82,6 +82,7 @@ export class NbTestAdapter { } cancellation.onCancellationRequested(() => this.cancel()); this.currentRun = this.testController.createTestRun(request); + this.currentRun.token.onCancellationRequested(() => this.cancel()); this.itemsToRun = new Set(); this.started = false; if (request.include) { @@ -105,7 +106,12 @@ export class NbTestAdapter { nestedClass = nestedClass.replace('$', '.'); } if (!cancellation.isCancellationRequested) { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass); + try { + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass); + } catch(err) { + // test state will be handled in the code below + console.log(err); + } } } } @@ -113,10 +119,15 @@ export class NbTestAdapter { this.testController.items.forEach(item => this.set(item, 'enqueued')); for (let workspaceFolder of workspace.workspaceFolders || []) { if (!cancellation.isCancellationRequested) { - if (testInParallel) { - await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects); - } else { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + try { + if (testInParallel) { + await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects); + } else { + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + } + } catch(err) { + // test state will be handled in the code below + console.log(err); } } }