Skip to content

Commit

Permalink
Avoid panics for failed AST parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rliebz committed Jan 25, 2024
1 parent dddd073 commit afbbe7f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion be/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package be
import (
"fmt"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -53,11 +54,20 @@ func applyVariadicBooleanLogic(
for i, result := range results {
out.Ok = apply(out.Ok, result.Ok)

// Not sure why AST parsing would fail, but sometimes it does. Seems to be
// environment dependent rather than code dependent.
var arg string
if len(args) > i {
arg = fmt.Sprintf("`%s`", args[i])
} else {
arg = strconv.Itoa(i)
}

var b strings.Builder
if i != 0 {
b.WriteString("\n\n")
}
fmt.Fprintf(&b, "assertion `%s` is %t", args[i], result.Ok)
fmt.Fprintf(&b, "assertion %s is %t", arg, result.Ok)
b.WriteString("\n\t")
b.WriteString(indentString(result.Message))

Expand Down

0 comments on commit afbbe7f

Please sign in to comment.