From 98c287bfc9a7838cabd3d1c0e6ea29e37666a50d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:18:44 +0000 Subject: [PATCH 1/2] Initial plan From 93c0178a8a48f792bea1546ea4e8cd3f06cf8bf8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:25:30 +0000 Subject: [PATCH 2/2] Fix CommandFailed event not emitted when project/document not opened The @microsoft/polyglot-notebooks library changed behavior so that errors thrown inside command handlers are now swallowed via .catch() instead of being passed to context.fail(). This caused the 'cannot open document if there is no open project' test to fail because no CommandFailed event was emitted. Fix by replacing throw calls with explicit context.fail() calls in all command handlers in projectKernel.ts. Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com> --- .../src/projectKernel.ts | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/microsoft-trydotnet-editor/src/projectKernel.ts b/src/microsoft-trydotnet-editor/src/projectKernel.ts index 04efe99cd..c5474beb0 100644 --- a/src/microsoft-trydotnet-editor/src/projectKernel.ts +++ b/src/microsoft-trydotnet-editor/src/projectKernel.ts @@ -25,9 +25,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.SubmitCodeType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleSubmitCode(commandInvocation); } }); @@ -44,7 +49,10 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.OpenDocumentType, handle: async (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return; + } await this.handleOpenDocument(commandInvocation); let command = commandInvocation.commandEnvelope.command; this._openDocument = { @@ -60,8 +68,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestDiagnosticsType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestDiagnostics(commandInvocation); } }); @@ -69,8 +83,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestCompletionsType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestCompletions(commandInvocation); } }); @@ -78,8 +98,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestHoverTextType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestHoverText(commandInvocation); } }); @@ -87,27 +113,19 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestSignatureHelpType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestSignatureHelp(commandInvocation); } }); } - protected throwIfProjectIsNotOpened() { - if (!this._project) { - // todo : align error message with .NET - throw new Error(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); - } - } - - protected throwIffDocumentIsNotOpened() { - if (!this._openDocument) { - // todo : align error message with .NET - throw new Error(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); - } - } - protected abstract handleOpenProject(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise; protected abstract handleRequestDiagnostics(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise; protected abstract handleRequestCompletions(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise;