Scenario
When creating code insight to detect and track patterns, it is possible to encounter the following error.
Troubleshooting Steps
- Search the sourcegraph code base for reference to the
createAndAttachSeries
function to help understand and know the source of the error.
-
The function first validates the query by parsing it using either
querybuilder.ParseComputeQuery
orquerybuilder.ParseQuery
depending on whether the series has aGroupBy
field orGeneratedFromCaptureGroups
field respectively. If there is an error during validation, the function returns an error. - The function checks if the series has a
GeneratedFromCaptureGroups
field, and if so, sets thedynamic
variable to that value.
-
- Next, check that your search query is valid and that you are passing in the right parameters.
Solution
This error message "CreateAndAttachSeries: query validation: compute.Parse: compute endpoint expects nonempty pattern"
is indicating that the function is trying to execute a capture group search for a specific repository, but the search query passed to the compute endpoint is not valid.
To resolve this issue, you will need to ensure that the search query contains at least a regular expression capture group. The capture group cannot match file or repository names, it can match only the file contents. Below is an example of a search query with a capture group that generates insights to check that vulnerable versions of log4j are removed and only fixed versions appear.
lang:gradle org\.apache\.logging\.log4j['"] 2\.(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16)(\.[0-9]+) patterntype:regexp
It captures the version number of the log4j library.
The capture group is defined by the parentheses ()
. In this case, it captures the version number of log4j library in the format of 2.(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16)(\.[0-9]+)
, where the first capture group 2.(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16)
matches the major version (2) and the minor version (0-16) and the second capture group (\.[0-9]+)
matches the patch version (a dot followed by one or more digits).