feat: print all locals errors when there is a circular error (#11527)

pull/11539/head
teddylear 4 years ago committed by GitHub
parent 4550d9ddae
commit 1d01ad3651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
locals {
timestamp = formatdate("YYYY-MM-DDX", timestamp())
other_local = "test-${local.timestamp}"
}

@ -33,6 +33,9 @@ func TestValidateCommand(t *testing.T) {
// wrong packer block
{path: filepath.Join(testFixture("validate", "invalid_packer_block.pkr.hcl")), exitCode: 1},
// Should return multiple errors,
{path: filepath.Join(testFixture("validate", "circular_error.pkr.hcl")), exitCode: 1},
}
for _, tc := range tt {

@ -225,6 +225,21 @@ func (c *PackerConfig) parseLocalVariables(f *hcl.File) ([]*LocalBlock, hcl.Diag
return locals, diags
}
func (c *PackerConfig) evaluateAllLocalVariables(locals []*LocalBlock) hcl.Diagnostics {
var local_diags hcl.Diagnostics
// divide by 2 so that you don't get duplicate locals
// appear to have double locals in LocalBlock, not sure if intentional
for i := 0; i < len(locals)/2; i++ {
diags := c.evaluateLocalVariable(locals[i])
if diags.HasErrors() {
local_diags = append(local_diags, diags...)
}
}
return local_diags
}
func (c *PackerConfig) evaluateLocalVariables(locals []*LocalBlock) hcl.Diagnostics {
var diags hcl.Diagnostics
@ -245,7 +260,7 @@ func (c *PackerConfig) evaluateLocalVariables(locals []*LocalBlock) hcl.Diagnost
if previousL == len(locals) {
if retry == 100 {
// To get to this point, locals must have a circle dependency
return append(diags, moreDiags...)
return c.evaluateAllLocalVariables(locals)
}
retry++
}

Loading…
Cancel
Save