Skip to content

Commit

Permalink
Fix-80080 Show more detailed error message for "Regex parse error" in…
Browse files Browse the repository at this point in the history
… search (#80495)

* Added buildRegexParseError for better parsing error message

* Fixed message

* Review #1 changes

* Changed error message as per review #2

* Review #3 changes

* Review #4 changes
  • Loading branch information
skprabhanjan authored and roblourens committed Sep 16, 2019
1 parent 50568aa commit 2d6ab9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function rgErrorMsgForDisplay(msg: string): Maybe<SearchError> {
const firstLine = lines[0].trim();

if (lines.some(l => startsWith(l, 'regex parse error'))) {
return new SearchError('Regex parse error', SearchErrorCode.regexParseError);
return new SearchError(buildRegexParseError(lines), SearchErrorCode.regexParseError);
}

const match = firstLine.match(/grep config error: unknown encoding: (.*)/);
Expand All @@ -150,6 +150,21 @@ export function rgErrorMsgForDisplay(msg: string): Maybe<SearchError> {
return undefined;
}

export function buildRegexParseError(lines: string[]): string {
let errorMessage: string[] = ['Regex parse error'];
let pcre2ErrorLine = lines.filter(l => (startsWith(l, 'PCRE2:')));
if (pcre2ErrorLine.length >= 1) {
let pcre2ErrorMessage = pcre2ErrorLine[0].replace('PCRE2:', '');
if (pcre2ErrorMessage.indexOf(':') !== -1 && pcre2ErrorMessage.split(':').length >= 2) {
let pcre2ActualErrorMessage = pcre2ErrorMessage.split(':')[1];
errorMessage.push(':' + pcre2ActualErrorMessage);
}
}

return errorMessage.join('');
}


export class RipgrepParser extends EventEmitter {
private remainder = '';
private isDone = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ suite('Search-integration', function () {
});
});

test('invalid regex', () => {
test('invalid regex case 1', () => {
const config: ITextQuery = {
type: QueryType.Text,
folderQueries: ROOT_FOLDER_QUERY,
Expand All @@ -387,11 +387,30 @@ suite('Search-integration', function () {
throw new Error('expected fail');
}, err => {
const searchError = deserializeSearchError(err.message);
assert.equal(searchError.message, 'Regex parse error');
let regexParseErrorForUnclosedParenthesis = 'Regex parse error: unmatched closing parenthesis';
assert.equal(searchError.message, regexParseErrorForUnclosedParenthesis);
assert.equal(searchError.code, SearchErrorCode.regexParseError);
});
});

test('invalid regex case 2', () => {
const config: ITextQuery = {
type: QueryType.Text,
folderQueries: ROOT_FOLDER_QUERY,
contentPattern: { pattern: '(?<!a.*)', isRegExp: true },
};

return doSearchTest(config, 0).then(() => {
throw new Error('expected fail');
}, err => {
const searchError = deserializeSearchError(err.message);
let regexParseErrorForLookAround = 'Regex parse error: lookbehind assertion is not fixed length';
assert.equal(searchError.message, regexParseErrorForLookAround);
assert.equal(searchError.code, SearchErrorCode.regexParseError);
});
});


test('invalid glob', () => {
const config: ITextQuery = {
type: QueryType.Text,
Expand Down

0 comments on commit 2d6ab9c

Please sign in to comment.