Skip to content

Commit

Permalink
Fix Cannot Read property 'cwd' of undefined
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#9743 by improving check for taskConfig.options.cwd from eclipse-theia#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 <[email protected]>
  • Loading branch information
kenneth-marut-work committed Jul 15, 2021
1 parent 3181ed3 commit 8f7ebb6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/task/src/browser/task-terminal-widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8f7ebb6

Please sign in to comment.