Skip to content

Commit

Permalink
configs/configupgrade: fix panic on nil hilNode (#22181)
Browse files Browse the repository at this point in the history
In some cases (see #22020 for a specific example), the parsed hilNode
can be nil. This causes a series of panics. Instead, return an error and
move on.
  • Loading branch information
mildwonkey authored Jul 23, 2019
1 parent eaa5724 commit 66f4a48
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions configs/configupgrade/upgrade_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ Value:
Subject: hcl1PosRange(filename, tv.Pos).Ptr(),
})
}
if _, ok := hilNode.(*hilast.Output); !ok {
// hil.Parse usually produces an output, but it can sometimes
// produce an isolated expression if the input is entirely
// a single interpolation.
hilNode = &hilast.Output{
Exprs: []hilast.Node{hilNode},
Posx: hilNode.Pos(),
if hilNode != nil {
if _, ok := hilNode.(*hilast.Output); !ok {
// hil.Parse usually produces an output, but it can sometimes
// produce an isolated expression if the input is entirely
// a single interpolation.
if hilNode != nil {
hilNode = &hilast.Output{
Exprs: []hilast.Node{hilNode},
Posx: hilNode.Pos(),
}
}
}
interpDiags := upgradeHeredocBody(&buf, hilNode.(*hilast.Output), filename, an)
diags = diags.Append(interpDiags)
}
interpDiags := upgradeHeredocBody(&buf, hilNode.(*hilast.Output), filename, an)
diags = diags.Append(interpDiags)
}
if !strings.HasSuffix(body, "\n") {
// The versions of HCL1 vendored into Terraform <=0.11
Expand Down

0 comments on commit 66f4a48

Please sign in to comment.