-
Notifications
You must be signed in to change notification settings - Fork 34k
Fix crash when problemMatcher has empty pattern array #256612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: anthonykim1 <[email protected]>
@@ -987,6 +987,10 @@ export class ProblemPatternParser extends Parser { | |||
} | |||
result.push(pattern); | |||
} | |||
if (result.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be checking for result === undefined or result.length === 0, since we should cover both when problem is defined as empty array and also if it is not provided by user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the guard clauses to check for both undefined and empty arrays as suggested. Changed if (result.length === 0)
to if (!result || result.length === 0)
and similarly for the validateProblemPattern function. This provides better defensive programming against cases where the array might be undefined or null. Commit: 79a1fe8
@@ -1042,6 +1046,10 @@ export class ProblemPatternParser extends Parser { | |||
} | |||
|
|||
private validateProblemPattern(values: IProblemPattern[]): boolean { | |||
if (values.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check for when values is passed in as null and handle this gracefully so that we don't crash on values[0].kind
Should we be considering to mark empty problem pattern as a valid problem pattern? @meganrogge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation already handles null values with the !values
check on line 1049. The guard clause if (!values || values.length === 0)
covers null, undefined, and empty array cases before accessing values[0].kind
on line 1054. The design question about whether empty patterns should be valid is for @meganrogge to address.
Co-authored-by: anthonykim1 <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
@meganrogge I think these are pretty safe to go in, and would prevent us from crashing of trying to access |
Problem
When a task configuration contains a
problemMatcher
with an emptypattern: []
array, VS Code crashes with the error:This occurs when users define tasks like:
Root Cause
The crash occurs in two functions in
problemMatcher.ts
:createMultiLineProblemPattern()
at line 990:if (result[0].kind === undefined)
validateProblemPattern()
at line 1046:const locationKind = (values[0].kind === undefined)
Both functions attempt to access the first element of an array without checking if the array is empty.
Solution
Added guard clauses to both functions to check for empty arrays before accessing
[0]
:createMultiLineProblemPattern
: Checkresult.length === 0
before accessingresult[0].kind
validateProblemPattern
: Checkvalues.length === 0
before accessingvalues[0].kind
Both functions now return appropriate error messages instead of crashing:
Changes
createMultiLineProblemPattern
with 4-line guard clausevalidateProblemPattern
with 4-line guard clauseTesting
Created comprehensive test coverage including:
Before fix: Crashes with
Cannot read properties of undefined (reading 'kind')
After fix: Returns graceful error message guiding the user
Fixes #246889.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.org
node-gyp
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.