Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stack block with unrecognized blocks #358

Merged
merged 16 commits into from
May 30, 2022
3 changes: 3 additions & 0 deletions errors/list_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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