Skip to content

Commit 24d1bbe

Browse files
committed
Make sure unknown search errors and cancellation is logged correctly
microsoft#99634
1 parent 02b67ca commit 24d1bbe

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/vs/workbench/services/search/common/search.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Event } from 'vs/base/common/event';
1818
import { relative } from 'vs/base/common/path';
1919
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2020
import { ResourceGlobMatcher } from 'vs/workbench/common/resources';
21+
import { isPromiseCanceledError } from 'vs/base/common/errors';
2122

2223
export const VIEWLET_ID = 'workbench.view.search';
2324
export const PANEL_ID = 'workbench.panel.search';
@@ -422,7 +423,8 @@ export enum SearchErrorCode {
422423
globParseError,
423424
invalidLiteral,
424425
rgProcessError,
425-
other
426+
other,
427+
canceled
426428
}
427429

428430
export class SearchError extends Error {
@@ -431,7 +433,13 @@ export class SearchError extends Error {
431433
}
432434
}
433435

434-
export function deserializeSearchError(errorMsg: string): SearchError {
436+
export function deserializeSearchError(error: Error): SearchError {
437+
const errorMsg = error.message;
438+
439+
if (isPromiseCanceledError(error)) {
440+
return new SearchError(errorMsg, SearchErrorCode.canceled);
441+
}
442+
435443
try {
436444
const details = JSON.parse(errorMsg);
437445
return new SearchError(details.message, details.code);

src/vs/workbench/services/search/common/searchService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export class SearchService extends Disposable implements ISearchService {
260260
}, err => {
261261
const endToEndTime = e2eSW.elapsed();
262262
this.logService.trace(`SearchService#search: ${endToEndTime}ms`);
263-
const searchError = deserializeSearchError(err.message);
263+
const searchError = deserializeSearchError(err);
264+
this.logService.trace(`SearchService#searchError: ${searchError.message}`);
264265
this.sendTelemetry(query, endToEndTime, undefined, searchError);
265266

266267
throw searchError;
@@ -387,7 +388,8 @@ export class SearchService extends Disposable implements ISearchService {
387388
err.code === SearchErrorCode.globParseError ? 'glob' :
388389
err.code === SearchErrorCode.invalidLiteral ? 'literal' :
389390
err.code === SearchErrorCode.other ? 'other' :
390-
'unknown';
391+
err.code === SearchErrorCode.canceled ? 'canceled' :
392+
'unknown';
391393
}
392394

393395
type TextSearchCompleteClassification = {

src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ suite('TextSearch-integration', function () {
370370
return doSearchTest(config, 0).then(() => {
371371
throw new Error('expected fail');
372372
}, err => {
373-
const searchError = deserializeSearchError(err.message);
373+
const searchError = deserializeSearchError(err);
374374
assert.equal(searchError.message, 'Unknown encoding: invalidEncoding');
375375
assert.equal(searchError.code, SearchErrorCode.unknownEncoding);
376376
});
@@ -386,7 +386,7 @@ suite('TextSearch-integration', function () {
386386
return doSearchTest(config, 0).then(() => {
387387
throw new Error('expected fail');
388388
}, err => {
389-
const searchError = deserializeSearchError(err.message);
389+
const searchError = deserializeSearchError(err);
390390
let regexParseErrorForUnclosedParenthesis = 'Regex parse error: unmatched closing parenthesis';
391391
assert.equal(searchError.message, regexParseErrorForUnclosedParenthesis);
392392
assert.equal(searchError.code, SearchErrorCode.regexParseError);
@@ -403,7 +403,7 @@ suite('TextSearch-integration', function () {
403403
return doSearchTest(config, 0).then(() => {
404404
throw new Error('expected fail');
405405
}, err => {
406-
const searchError = deserializeSearchError(err.message);
406+
const searchError = deserializeSearchError(err);
407407
let regexParseErrorForLookAround = 'Regex parse error: lookbehind assertion is not fixed length';
408408
assert.equal(searchError.message, regexParseErrorForLookAround);
409409
assert.equal(searchError.code, SearchErrorCode.regexParseError);
@@ -424,7 +424,7 @@ suite('TextSearch-integration', function () {
424424
return doSearchTest(config, 0).then(() => {
425425
throw new Error('expected fail');
426426
}, err => {
427-
const searchError = deserializeSearchError(err.message);
427+
const searchError = deserializeSearchError(err);
428428
assert.equal(searchError.message, 'Error parsing glob \'/{{}\': nested alternate groups are not allowed');
429429
assert.equal(searchError.code, SearchErrorCode.globParseError);
430430
});

0 commit comments

Comments
 (0)