From a7c35d7a05542ccced46c808874c000ad60ca2f0 Mon Sep 17 00:00:00 2001 From: kenneth-marut-work <62660714+kenneth-marut-work@users.noreply.github.com> Date: Fri, 16 Jul 2021 04:45:53 -0500 Subject: [PATCH] Fix Cannot Read property 'cwd' of undefined (#9747) Fixes #9743 by improving check for taskConfig.options.cwd from #9695. Also ensures that lastCwd field on terminal-widget is never undefined as to ensure get cwd() will always return a URI. Signed-off-by: Kenneth Marut --- packages/task/src/browser/task-terminal-widget-manager.ts | 3 ++- packages/terminal/src/browser/base/terminal-widget.ts | 2 +- packages/terminal/src/browser/terminal-widget-impl.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/task/src/browser/task-terminal-widget-manager.ts b/packages/task/src/browser/task-terminal-widget-manager.ts index 72d381e49e121..be39786410df0 100644 --- a/packages/task/src/browser/task-terminal-widget-manager.ts +++ b/packages/task/src/browser/task-terminal-widget-manager.ts @@ -196,7 +196,8 @@ export class TaskTerminalWidgetManager { } // we are unable to find a terminal widget to run the task, or `taskPresentation === 'new'` - const lastCwd = new URI(taskConfig?.options.cwd); + const lastCwd = taskConfig?.options?.cwd ? new URI(taskConfig.options.cwd) : new URI(); + if (!reusableTerminalWidget) { const widget = await this.newTaskTerminal(factoryOptions); widget.lastCwd = lastCwd; diff --git a/packages/terminal/src/browser/base/terminal-widget.ts b/packages/terminal/src/browser/base/terminal-widget.ts index 3f4d50bde9e96..d1a7378feb171 100644 --- a/packages/terminal/src/browser/base/terminal-widget.ts +++ b/packages/terminal/src/browser/base/terminal-widget.ts @@ -46,7 +46,7 @@ export abstract class TerminalWidget extends BaseWidget { abstract readonly dimensions: TerminalDimensions; /** The last CWD assigned to the terminal, useful when attempting getCwdURI on a task terminal fails */ - lastCwd: URI | undefined; + lastCwd: URI; /** * Start terminal and return terminal id. diff --git a/packages/terminal/src/browser/terminal-widget-impl.ts b/packages/terminal/src/browser/terminal-widget-impl.ts index de9e0fbdb04f6..89b051be547ba 100644 --- a/packages/terminal/src/browser/terminal-widget-impl.ts +++ b/packages/terminal/src/browser/terminal-widget-impl.ts @@ -61,7 +61,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget protected hoverMessage: HTMLDivElement; protected lastTouchEnd: TouchEvent | undefined; protected isAttachedCloseListener: boolean = false; - lastCwd: URI; + lastCwd = new URI(); @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; @inject(WebSocketConnectionProvider) protected readonly webSocketConnectionProvider: WebSocketConnectionProvider;