@@ -23,6 +23,7 @@ import which from "which";
2323import { existsSync } from "fs" ;
2424import { join } from "path" ;
2525import { PythonExtension } from "@vscode/python-extension" ;
26+ import { unknownErrorToString } from "../utils/errorHelper.mjs" ;
2627
2728interface SubmitMessageValue {
2829 projectName : string ;
@@ -379,7 +380,18 @@ print("Finished.")\r\n`;
379380 const html = await this . _getHtmlForWebview ( this . _panel . webview ) ;
380381
381382 if ( html !== "" ) {
382- this . _panel . webview . html = html ;
383+ try {
384+ this . _panel . webview . html = html ;
385+ } catch ( error ) {
386+ this . _logger . error (
387+ "Failed to set webview html. Webview might have been disposed. Error: " ,
388+ unknownErrorToString ( error )
389+ ) ;
390+ // properly dispose panel
391+ this . dispose ( ) ;
392+
393+ return ;
394+ }
383395 await this . _updateTheme ( ) ;
384396 } else {
385397 void window . showErrorMessage (
@@ -390,14 +402,23 @@ print("Finished.")\r\n`;
390402 }
391403
392404 private async _updateTheme ( ) : Promise < void > {
393- await this . _panel . webview . postMessage ( {
394- command : "setTheme" ,
395- theme :
396- window . activeColorTheme . kind === ColorThemeKind . Dark ||
397- window . activeColorTheme . kind === ColorThemeKind . HighContrast
398- ? "dark"
399- : "light" ,
400- } ) ;
405+ try {
406+ await this . _panel . webview . postMessage ( {
407+ command : "setTheme" ,
408+ theme :
409+ window . activeColorTheme . kind === ColorThemeKind . Dark ||
410+ window . activeColorTheme . kind === ColorThemeKind . HighContrast
411+ ? "dark"
412+ : "light" ,
413+ } ) ;
414+ } catch ( error ) {
415+ this . _logger . error (
416+ "Failed to update theme in webview. Webview might have been disposed. Error:" ,
417+ unknownErrorToString ( error )
418+ ) ;
419+ // properly dispose panel
420+ this . dispose ( ) ;
421+ }
401422 }
402423
403424 public dispose ( ) : void {
0 commit comments