Skip to content

Commit 5af0900

Browse files
authored
Catch and swallow errors during terminal persistence (microsoft#136804)
1 parent f4af3cb commit 5af0900

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/vs/workbench/contrib/terminal/browser/terminalService.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { ILifecycleService, ShutdownReason, WillShutdownEvent } from 'vs/workben
5050
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
5151
import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
5252
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
53+
import { ILogService } from 'vs/platform/log/common/log';
5354

5455
export class TerminalService implements ITerminalService {
5556
declare _serviceBrand: undefined;
@@ -160,6 +161,7 @@ export class TerminalService implements ITerminalService {
160161
@IContextKeyService private _contextKeyService: IContextKeyService,
161162
@ILabelService labelService: ILabelService,
162163
@ILifecycleService lifecycleService: ILifecycleService,
164+
@ILogService private readonly _logService: ILogService,
163165
@IDialogService private _dialogService: IDialogService,
164166
@IInstantiationService private _instantiationService: IInstantiationService,
165167
@IRemoteAgentService private _remoteAgentService: IRemoteAgentService,
@@ -585,22 +587,27 @@ export class TerminalService implements ITerminalService {
585587

586588
// Persist terminal _buffer state_, note that even if this happens the dirty terminal prompt
587589
// still shows as that cannot be revived
588-
this._shutdownWindowCount = await this._nativeDelegate?.getWindowCount();
589-
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
590-
if (shouldReviveProcesses) {
591-
await this._primaryOffProcessTerminalService?.persistTerminalState();
592-
}
593-
594-
// Persist terminal _processes_
595-
const shouldPersistProcesses = this._configHelper.config.enablePersistentSessions && reason === ShutdownReason.RELOAD;
596-
if (!shouldPersistProcesses) {
597-
const hasDirtyInstances = (
598-
(this.configHelper.config.confirmOnExit === 'always' && this.instances.length > 0) ||
599-
(this.configHelper.config.confirmOnExit === 'hasChildProcesses' && this.instances.some(e => e.hasChildProcesses))
600-
);
601-
if (hasDirtyInstances) {
602-
return this._onBeforeShutdownConfirmation(reason);
590+
try {
591+
this._shutdownWindowCount = await this._nativeDelegate?.getWindowCount();
592+
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
593+
if (shouldReviveProcesses) {
594+
await this._primaryOffProcessTerminalService?.persistTerminalState();
595+
}
596+
597+
// Persist terminal _processes_
598+
const shouldPersistProcesses = this._configHelper.config.enablePersistentSessions && reason === ShutdownReason.RELOAD;
599+
if (!shouldPersistProcesses) {
600+
const hasDirtyInstances = (
601+
(this.configHelper.config.confirmOnExit === 'always' && this.instances.length > 0) ||
602+
(this.configHelper.config.confirmOnExit === 'hasChildProcesses' && this.instances.some(e => e.hasChildProcesses))
603+
);
604+
if (hasDirtyInstances) {
605+
return this._onBeforeShutdownConfirmation(reason);
606+
}
603607
}
608+
} catch (err: unknown) {
609+
// Swallow as exceptions should not cause a veto to prevent shutdown
610+
this._logService.warn('Exception occurred during terminal shutdown', err);
604611
}
605612

606613
this._isShuttingDown = true;

0 commit comments

Comments
 (0)