From 3f4b4a35942ab0386e9e8c1bc1767b83d39ccfa7 Mon Sep 17 00:00:00 2001 From: Tiago de Bem Natel de Moura Date: Mon, 30 May 2022 09:57:40 +0100 Subject: [PATCH] fix: stack block with unrecognized blocks (#358) --- errors/list_test.go | 3 +++ hcl/hcl.go | 9 ++++++++- hcl/hcl_test.go | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/errors/list_test.go b/errors/list_test.go index 9d9a2f422..0344c81f5 100644 --- a/errors/list_test.go +++ b/errors/list_test.go @@ -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())) diff --git a/hcl/hcl.go b/hcl/hcl.go index cec229199..900807ccc 100644 --- a/hcl/hcl.go +++ b/hcl/hcl.go @@ -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.") diff --git a/hcl/hcl_test.go b/hcl/hcl_test.go index e9151ed53..329420d32 100644 --- a/hcl/hcl_test.go +++ b/hcl/hcl_test.go @@ -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{