configs/configupgrade: fix panic on nil hilNode (#22181)
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.
This commit is contained in:
parent
eaa57243c7
commit
66f4a48b8c
|
@ -110,18 +110,22 @@ Value:
|
||||||
Subject: hcl1PosRange(filename, tv.Pos).Ptr(),
|
Subject: hcl1PosRange(filename, tv.Pos).Ptr(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if hilNode != nil {
|
||||||
if _, ok := hilNode.(*hilast.Output); !ok {
|
if _, ok := hilNode.(*hilast.Output); !ok {
|
||||||
// hil.Parse usually produces an output, but it can sometimes
|
// hil.Parse usually produces an output, but it can sometimes
|
||||||
// produce an isolated expression if the input is entirely
|
// produce an isolated expression if the input is entirely
|
||||||
// a single interpolation.
|
// a single interpolation.
|
||||||
|
if hilNode != nil {
|
||||||
hilNode = &hilast.Output{
|
hilNode = &hilast.Output{
|
||||||
Exprs: []hilast.Node{hilNode},
|
Exprs: []hilast.Node{hilNode},
|
||||||
Posx: hilNode.Pos(),
|
Posx: hilNode.Pos(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
interpDiags := upgradeHeredocBody(&buf, hilNode.(*hilast.Output), filename, an)
|
interpDiags := upgradeHeredocBody(&buf, hilNode.(*hilast.Output), filename, an)
|
||||||
diags = diags.Append(interpDiags)
|
diags = diags.Append(interpDiags)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !strings.HasSuffix(body, "\n") {
|
if !strings.HasSuffix(body, "\n") {
|
||||||
// The versions of HCL1 vendored into Terraform <=0.11
|
// The versions of HCL1 vendored into Terraform <=0.11
|
||||||
// incorrectly allowed the end marker to appear at the end of
|
// incorrectly allowed the end marker to appear at the end of
|
||||||
|
|
Loading…
Reference in New Issue