Catch and swallow errors during terminal persistence (#136804)

Part of #137468
This commit is contained in:
Daniel Imms 2021-11-09 17:34:14 -08:00
parent 5128d2c32c
commit cce62293cd

View file

@ -42,6 +42,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { TerminalProfileQuickpick } from 'vs/workbench/contrib/terminal/browser/terminalProfileQuickpick';
import { IKeyMods } from 'vs/base/parts/quickinput/common/quickInput';
import { ILogService } from 'vs/platform/log/common/log';
export class TerminalService implements ITerminalService {
declare _serviceBrand: undefined;
@ -136,6 +137,7 @@ export class TerminalService implements ITerminalService {
constructor(
@IContextKeyService private _contextKeyService: IContextKeyService,
@ILifecycleService lifecycleService: ILifecycleService,
@ILogService private readonly _logService: ILogService,
@IDialogService private _dialogService: IDialogService,
@IInstantiationService private _instantiationService: IInstantiationService,
@IRemoteAgentService private _remoteAgentService: IRemoteAgentService,
@ -498,22 +500,27 @@ export class TerminalService implements ITerminalService {
// Persist terminal _buffer state_, note that even if this happens the dirty terminal prompt
// still shows as that cannot be revived
this._shutdownWindowCount = await this._nativeDelegate?.getWindowCount();
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
if (shouldReviveProcesses) {
await this._primaryBackend?.persistTerminalState();
}
// Persist terminal _processes_
const shouldPersistProcesses = this._configHelper.config.enablePersistentSessions && reason === ShutdownReason.RELOAD;
if (!shouldPersistProcesses) {
const hasDirtyInstances = (
(this.configHelper.config.confirmOnExit === 'always' && this.instances.length > 0) ||
(this.configHelper.config.confirmOnExit === 'hasChildProcesses' && this.instances.some(e => e.hasChildProcesses))
);
if (hasDirtyInstances) {
return this._onBeforeShutdownConfirmation(reason);
try {
this._shutdownWindowCount = await this._nativeDelegate?.getWindowCount();
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
if (shouldReviveProcesses) {
await this._primaryBackend?.persistTerminalState();
}
// Persist terminal _processes_
const shouldPersistProcesses = this._configHelper.config.enablePersistentSessions && reason === ShutdownReason.RELOAD;
if (!shouldPersistProcesses) {
const hasDirtyInstances = (
(this.configHelper.config.confirmOnExit === 'always' && this.instances.length > 0) ||
(this.configHelper.config.confirmOnExit === 'hasChildProcesses' && this.instances.some(e => e.hasChildProcesses))
);
if (hasDirtyInstances) {
return this._onBeforeShutdownConfirmation(reason);
}
}
} catch (err: unknown) {
// Swallow as exceptions should not cause a veto to prevent shutdown
this._logService.warn('Exception occurred during terminal shutdown', err);
}
this._isShuttingDown = true;