Skip to content

Commit ae03121

Browse files
Copilotanthonykim1
andauthored
Fix crash when problemMatcher has empty pattern array (microsoft#256612)
* Initial plan * Fix empty pattern array crash - add guard clauses Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> * Address review feedback: Add undefined checks to array validation Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
1 parent 57562a8 commit ae03121

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/vs/workbench/contrib/tasks/common/problemMatcher.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ export class ProblemPatternParser extends Parser {
987987
}
988988
result.push(pattern);
989989
}
990+
if (!result || result.length === 0) {
991+
this.error(localize('ProblemPatternParser.problemPattern.emptyPattern', 'The problem pattern is invalid. It must contain at least one pattern.'));
992+
return null;
993+
}
990994
if (result[0].kind === undefined) {
991995
result[0].kind = ProblemLocationKind.Location;
992996
}
@@ -1042,6 +1046,10 @@ export class ProblemPatternParser extends Parser {
10421046
}
10431047

10441048
private validateProblemPattern(values: IProblemPattern[]): boolean {
1049+
if (!values || values.length === 0) {
1050+
this.error(localize('ProblemPatternParser.problemPattern.emptyPattern', 'The problem pattern is invalid. It must contain at least one pattern.'));
1051+
return false;
1052+
}
10451053
let file: boolean = false, message: boolean = false, location: boolean = false, line: boolean = false;
10461054
const locationKind = (values[0].kind === undefined) ? ProblemLocationKind.Location : values[0].kind;
10471055

src/vs/workbench/contrib/tasks/test/common/problemMatcher.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,13 @@ suite('ProblemPatternParser', () => {
256256
assert.strictEqual(ValidationState.Error, reporter.state);
257257
assert(reporter.hasMessage('The problem pattern is invalid. It must have at least have a file and a message.'));
258258
});
259+
260+
test('empty pattern array should be handled gracefully', () => {
261+
const problemPattern: matchers.Config.MultiLineProblemPattern = [];
262+
const parsed = parser.parse(problemPattern);
263+
assert.strictEqual(null, parsed);
264+
assert.strictEqual(ValidationState.Error, reporter.state);
265+
assert(reporter.hasMessage('The problem pattern is invalid. It must contain at least one pattern.'));
266+
});
259267
});
260268
});

0 commit comments

Comments
 (0)