Skip to content

Commit

Permalink
Fix #136732
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Nov 9, 2021
1 parent f18b29e commit bf14040
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/vs/workbench/contrib/logs/common/logs.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { IFileService, whenProviderRegistered } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { IOutputChannelRegistry, Extensions as OutputExt } from 'vs/workbench/services/output/common/output';
import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { isWeb } from 'vs/base/common/platform';
Expand All @@ -24,8 +24,9 @@ import { LogsDataCleaner } from 'vs/workbench/contrib/logs/common/logsDataCleane
import { IOutputService } from 'vs/workbench/contrib/output/common/output';
import { supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
import { IProductService } from 'vs/platform/product/common/productService';
import { timeout } from 'vs/base/common/async';
import { getErrorMessage } from 'vs/base/common/errors';
import { createCancelablePromise, timeout } from 'vs/base/common/async';
import { canceled, getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors';
import { CancellationToken } from 'vs/base/common/cancellation';

const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.from(SetLogLevelAction), 'Developer: Set Log Level...', CATEGORIES.Developer.value);
Expand Down Expand Up @@ -99,24 +100,31 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
await whenProviderRegistered(file, this.fileService);
const outputChannelRegistry = Registry.as<IOutputChannelRegistry>(OutputExt.OutputChannels);
try {
await this.whenFileExists(file, 1);
const promise = createCancelablePromise(token => this.whenFileExists(file, 1, token));
this._register(toDisposable(() => promise.cancel()));
await promise;
outputChannelRegistry.registerChannel({ id, label, file, log: true });
} catch (error) {
this.logService.error('Error while registering log channel', file.toString(), getErrorMessage(error));
if (!isPromiseCanceledError(error)) {
this.logService.error('Error while registering log channel', file.toString(), getErrorMessage(error));
}
}
}

private async whenFileExists(file: URI, trial: number): Promise<void> {
private async whenFileExists(file: URI, trial: number, token: CancellationToken): Promise<void> {
const exists = await this.fileService.exists(file);
if (exists) {
return;
}
if (token.isCancellationRequested) {
throw canceled();
}
if (trial > 10) {
throw new Error(`Timed out while waiting for file to be created`);
}
this.logService.debug(`[Registering Log Channel] File does not exist. Waiting for 1s to retry.`, file.toString());
await timeout(1000);
await this.whenFileExists(file, trial + 1);
await timeout(1000, token);
await this.whenFileExists(file, trial + 1, token);
}

}
Expand Down

0 comments on commit bf14040

Please sign in to comment.