Skip to content

Commit aec70d0

Browse files
authored
Ensure we handle errors when checking support for LS (microsoft#3620)
For microsoft#2729
1 parent 93524ff commit aec70d0

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

src/client/activation/languageServer/languageServerCompatibilityService.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { inject, injectable } from 'inversify';
77
import { IDotNetCompatibilityService } from '../../common/dotnet/types';
8+
import { traceError } from '../../common/logger';
89
import { sendTelemetryEvent } from '../../telemetry';
910
import { PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED } from '../../telemetry/constants';
1011
import { ILanguageServerCompatibilityService } from '../types';
@@ -13,8 +14,14 @@ import { ILanguageServerCompatibilityService } from '../types';
1314
export class LanguageServerCompatibilityService implements ILanguageServerCompatibilityService {
1415
constructor(@inject(IDotNetCompatibilityService) private readonly dotnetCompatibility: IDotNetCompatibilityService) { }
1516
public async isSupported(): Promise<boolean> {
16-
const supported = await this.dotnetCompatibility.isSupported();
17-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
18-
return supported;
17+
try {
18+
const supported = await this.dotnetCompatibility.isSupported();
19+
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
20+
return supported;
21+
} catch (ex) {
22+
traceError('Unable to determine whether LS is supported', ex);
23+
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' });
24+
return false;
25+
}
1926
}
2027
}

src/client/telemetry/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type LanguageServerErrorTelemetry = {
2929

3030
export type LanguageServePlatformSupported = {
3131
supported: boolean;
32+
failureType?: 'UnknownError';
3233
};
3334

3435
export type LinterTrigger = 'auto' | 'save';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { expect } from 'chai';
7+
import * as typeMoq from 'typemoq';
8+
import { LanguageServerCompatibilityService } from '../../../client/activation/languageServer/languageServerCompatibilityService';
9+
import { ILanguageServerCompatibilityService } from '../../../client/activation/types';
10+
import { IDotNetCompatibilityService } from '../../../client/common/dotnet/types';
11+
12+
suite('Language Server Support', () => {
13+
let compatService: typeMoq.IMock<IDotNetCompatibilityService>;
14+
let service: ILanguageServerCompatibilityService;
15+
setup(() => {
16+
compatService = typeMoq.Mock.ofType<IDotNetCompatibilityService>();
17+
service = new LanguageServerCompatibilityService(compatService.object);
18+
});
19+
test('Not supported if there are errors ', async () => {
20+
compatService.setup(c => c.isSupported()).returns(() => Promise.reject(new Error('kaboom')));
21+
const supported = await service.isSupported();
22+
expect(supported).to.equal(false, 'incorrect');
23+
});
24+
test('Not supported if there are not errors ', async () => {
25+
compatService.setup(c => c.isSupported()).returns(() => Promise.resolve(false));
26+
const supported = await service.isSupported();
27+
expect(supported).to.equal(false, 'incorrect');
28+
});
29+
test('Support if there are not errors ', async () => {
30+
compatService.setup(c => c.isSupported()).returns(() => Promise.resolve(true));
31+
const supported = await service.isSupported();
32+
expect(supported).to.equal(true, 'incorrect');
33+
});
34+
});

0 commit comments

Comments
 (0)