Fixes #136937: Do not log extension activation canceled error if the extension host is going down

This commit is contained in:
Alex Dima
2021-11-19 00:45:14 +01:00
parent 5d0da7b953
commit 7fbe563c0a
4 changed files with 32 additions and 18 deletions

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import type * as vscode from 'vscode';
import * as errors from 'vs/base/common/errors';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
@@ -169,7 +170,9 @@ export interface ExtensionActivationReason {
type ActivationIdAndReason = { id: ExtensionIdentifier, reason: ExtensionActivationReason };
export class ExtensionsActivator {
export class ExtensionsActivator implements IDisposable {
private _isDisposed: boolean;
private readonly _registry: ExtensionDescriptionRegistry;
private readonly _resolvedExtensionsSet: Set<string>;
@@ -189,6 +192,7 @@ export class ExtensionsActivator {
host: IExtensionsActivatorHost,
@ILogService private readonly _logService: ILogService
) {
this._isDisposed = false;
this._registry = registry;
this._resolvedExtensionsSet = new Set<string>();
resolvedExtensions.forEach((extensionId) => this._resolvedExtensionsSet.add(ExtensionIdentifier.toKey(extensionId)));
@@ -200,6 +204,10 @@ export class ExtensionsActivator {
this._alreadyActivatedEvents = Object.create(null);
}
public dispose(): void {
this._isDisposed = true;
}
public isActivated(extensionId: ExtensionIdentifier): boolean {
const extensionKey = ExtensionIdentifier.toKey(extensionId);
@@ -406,6 +414,12 @@ export class ExtensionsActivator {
error.stack = err.stack;
}
if (this._isDisposed && errors.isPromiseCanceledError(err)) {
// It is expected for ongoing activations to fail if the extension host is going down
// So simply ignore and don't log canceled errors in this case
return new FailedExtension(err);
}
this._host.onExtensionActivationError(
extensionId,
error,

View File

@@ -8,7 +8,7 @@ import * as path from 'vs/base/common/path';
import * as performance from 'vs/base/common/performance';
import { originalFSPath, joinPath, extUriBiasedIgnorePathCase } from 'vs/base/common/resources';
import { asPromise, Barrier, timeout } from 'vs/base/common/async';
import { dispose, toDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle';
import { dispose, toDisposable, Disposable } from 'vs/base/common/lifecycle';
import { TernarySearchTree } from 'vs/base/common/map';
import { URI, UriComponents } from 'vs/base/common/uri';
import { ILogService } from 'vs/platform/log/common/log';
@@ -110,8 +110,6 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
private _started: boolean;
private _remoteConnectionData: IRemoteConnectionData | null;
private readonly _disposables: DisposableStore;
constructor(
@IInstantiationService instaService: IInstantiationService,
@IHostUtils hostUtils: IHostUtils,
@@ -134,7 +132,6 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
this._logService = logService;
this._extHostTunnelService = extHostTunnelService;
this._extHostTerminalService = extHostTerminalService;
this._disposables = new DisposableStore();
this._mainThreadWorkspaceProxy = this._extHostContext.getProxy(MainContext.MainThreadWorkspace);
this._mainThreadTelemetryProxy = this._extHostContext.getProxy(MainContext.MainThreadTelemetry);
@@ -157,7 +154,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
const hostExtensions = new Set<string>();
this._initData.hostExtensions.forEach((extensionId) => hostExtensions.add(ExtensionIdentifier.toKey(extensionId)));
this._activator = new ExtensionsActivator(
this._activator = this._register(new ExtensionsActivator(
this._registry,
this._initData.resolvedExtensions,
this._initData.hostExtensions,
@@ -176,7 +173,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
}
},
this._logService
);
));
this._extensionPathIndex = null;
this._resolvers = Object.create(null);
this._started = false;
@@ -523,7 +520,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
this._logService.error(err);
});
this._disposables.add(this._extHostWorkspace.onDidChangeWorkspace((e) => this._handleWorkspaceContainsEagerExtensions(e.added)));
this._register(this._extHostWorkspace.onDidChangeWorkspace((e) => this._handleWorkspaceContainsEagerExtensions(e.added)));
const folders = this._extHostWorkspace.workspace ? this._extHostWorkspace.workspace.folders : [];
const workspaceContainsActivation = this._handleWorkspaceContainsEagerExtensions(folders);
const eagerExtensionsActivation = Promise.all([starActivation, workspaceContainsActivation]).then(() => { });
@@ -684,7 +681,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
}
try {
this._disposables.add(await this._extHostTunnelService.setTunnelExtensionFunctions(resolver));
this._register(await this._extHostTunnelService.setTunnelExtensionFunctions(resolver));
performance.mark(`code/extHost/willResolveAuthority/${authorityPrefix}`);
const result = await resolver.resolve(remoteAuthority, { resolveAttempt });
performance.mark(`code/extHost/didResolveAuthorityOK/${authorityPrefix}`);

View File

@@ -226,7 +226,7 @@ export class ExtHostTextEditorOptions {
// reflect the new tabSize value immediately
this._tabSize = tabSize;
}
this._warnOnError(this._proxy.$trySetOptions(this._id, {
this._warnOnError('setTabSize', this._proxy.$trySetOptions(this._id, {
tabSize: tabSize
}));
}
@@ -250,7 +250,7 @@ export class ExtHostTextEditorOptions {
// reflect the new insertSpaces value immediately
this._insertSpaces = insertSpaces;
}
this._warnOnError(this._proxy.$trySetOptions(this._id, {
this._warnOnError('setInsertSpaces', this._proxy.$trySetOptions(this._id, {
insertSpaces: insertSpaces
}));
}
@@ -263,7 +263,7 @@ export class ExtHostTextEditorOptions {
return;
}
this._cursorStyle = value;
this._warnOnError(this._proxy.$trySetOptions(this._id, {
this._warnOnError('setCursorStyle', this._proxy.$trySetOptions(this._id, {
cursorStyle: value
}));
}
@@ -276,7 +276,7 @@ export class ExtHostTextEditorOptions {
return;
}
this._lineNumbers = value;
this._warnOnError(this._proxy.$trySetOptions(this._id, {
this._warnOnError('setLineNumbers', this._proxy.$trySetOptions(this._id, {
lineNumbers: TypeConverters.TextEditorLineNumbersStyle.from(value)
}));
}
@@ -341,12 +341,15 @@ export class ExtHostTextEditorOptions {
}
if (hasUpdate) {
this._warnOnError(this._proxy.$trySetOptions(this._id, bulkConfigurationUpdate));
this._warnOnError('setOptions', this._proxy.$trySetOptions(this._id, bulkConfigurationUpdate));
}
}
private _warnOnError(promise: Promise<any>): void {
promise.catch(err => this._logService.warn(err));
private _warnOnError(action: string, promise: Promise<any>): void {
promise.catch(err => {
this._logService.warn(`ExtHostTextEditorOptions '${action}' failed:'`);
this._logService.warn(err);
});
}
}