Skip to content

Commit 0b185f0

Browse files
authored
feat: Wait longer to process JQ query (#3)
Some large files may take longer than 100ms. It also fixes a wrong log message, only in this file, there are more in other parts of the project. Before that: ``` ❯ terrascan scan -i tfplan -f large.tfplan.json 2024-08-30T10:30:07.848+0200 warn utils/jqhelper.go:56 error in processing jq query; error: '%v'context deadline exceeded 2024-08-30T10:30:07.848+0200 error cli/run.go:141 scan run failed{error 26 0 failed to decode processed jq output. error: 'unexpected end of JSON input'} ``` *Note the wrong log message* Increase the timeout to 1s it works.
2 parents 4e0794f + e7c9b55 commit 0b185f0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/utils/jqhelper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func JQFilterWithQuery(jqQuery string, jsonInput []byte) ([]byte, error) {
4444
}
4545

4646
// run jq query on input
47-
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
47+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
4848
defer cancel()
4949
iter := query.RunWithContext(ctx, input)
5050
for {
@@ -53,13 +53,13 @@ func JQFilterWithQuery(jqQuery string, jsonInput []byte) ([]byte, error) {
5353
break
5454
}
5555
if err, ok := v.(error); ok {
56-
zap.S().Warn("error in processing jq query; error: '%v'", err)
56+
zap.S().Warnf("error in processing jq query; error: '%v'", err)
5757
continue
5858
}
5959

6060
jqout, err := json.Marshal(v)
6161
if err != nil {
62-
zap.S().Warn("failed to encode jq output into JSON. error: '%v'", err)
62+
zap.S().Warnf("failed to encode jq output into JSON. error: '%v'", err)
6363
continue
6464
}
6565
processed = append(processed, jqout...)

0 commit comments

Comments
 (0)