mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 00:32:09 -04:00
feat: print all locals errors when there is a circular error (#11527)
This commit is contained in:
parent
4550d9ddae
commit
1d01ad3651
3 changed files with 24 additions and 1 deletions
5
command/test-fixtures/validate/circular_error.pkr.hcl
Normal file
5
command/test-fixtures/validate/circular_error.pkr.hcl
Normal file
|
|
@ -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…
Reference in a new issue