提交 2d6ab9cb 编写于 作者: P Prabhanjan S Koushik 提交者: Rob Lourens

Fix-80080 Show more detailed error message for "Regex parse error" in 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
上级 50568aa2
......@@ -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: (.*)/);
......@@ -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;
......
......@@ -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,
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册