Skip to content

Commit 4d9911b

Browse files
fix: check Fail before Pass (#904)
1 parent ff8507a commit 4d9911b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/terraform/parser.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ func (p *PlanParser) Parse(body string) ParseResult { //nolint:cyclop
169169
}
170170
var hasPlanError bool
171171
switch {
172-
case p.Pass.MatchString(firstMatchLine):
173-
result = lines[firstMatchLineIndex]
174172
case p.Fail.MatchString(firstMatchLine):
173+
// Fail should be checked before Pass
175174
hasPlanError = true
176175
result = strings.Join(trimBars(trimLastNewline(lines[firstMatchLineIndex:])), "\n")
176+
case p.Pass.MatchString(firstMatchLine):
177+
result = lines[firstMatchLineIndex]
177178
}
178179

179180
hasDestroy := p.HasDestroy.MatchString(firstMatchLine)
@@ -257,10 +258,11 @@ func (p *ApplyParser) Parse(body string) ParseResult {
257258
}
258259
}
259260
switch {
260-
case p.Pass.MatchString(line):
261-
result = lines[i]
262261
case p.Fail.MatchString(line):
262+
// Fail should be checked before Pass
263263
result = strings.Join(trimBars(trimLastNewline(lines[i:])), "\n")
264+
case p.Pass.MatchString(line):
265+
result = lines[i]
264266
}
265267
return ParseResult{
266268
Result: strings.TrimSpace(result),

0 commit comments

Comments
 (0)