Skip to content

Commit

Permalink
fix: stack block with unrecognized blocks (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki committed May 30, 2022
1 parent 07c9a37 commit 3f4b4a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions errors/list_test.go
Expand Up @@ -33,6 +33,9 @@ func TestEmptyErrorListReturnsEmptyErrors(t *testing.T) {
}

func TestErrorListReturnsAllErrors(t *testing.T) {
// This test was updated to reflect the changed API of errors.List.Errors().
// Now it doesn't ignore errors anymore.

e := errors.L()

assert.EqualInts(t, 0, len(e.Errors()))
Expand Down
9 changes: 8 additions & 1 deletion hcl/hcl.go
Expand Up @@ -647,9 +647,16 @@ func parseStack(stack *Stack, stackblock *hclsyntax.Block) error {
Str("stack", stack.Name).
Logger()

errs := errors.L()

for _, block := range stackblock.Body.Blocks {
errs.Append(
errors.E(block.TypeRange, "unrecognized block %q", block.Type),
)
}

logger.Debug().Msg("Get stack attributes.")

errs := errors.L()
for _, attr := range sortedAttributes(stackblock.Body.Attributes) {
logger.Trace().Msg("Get attribute value.")

Expand Down
19 changes: 19 additions & 0 deletions hcl/hcl_test.go
Expand Up @@ -602,6 +602,25 @@ func TestHCLParserStack(t *testing.T) {
},
},
},
{
name: "stack with unrecognized blocks",
input: []cfgfile{
{
body: `
stack{
block1 {}
block2 {}
}
`,
},
},
want: want{
errs: []error{
errors.E(hcl.ErrTerramateSchema),
errors.E(hcl.ErrTerramateSchema),
},
},
},
{
name: "multiple stack blocks",
input: []cfgfile{
Expand Down

0 comments on commit 3f4b4a3

Please sign in to comment.