feat(misconf): log causes of HCL file parsing errors (#7634)

Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
Co-authored-by: Simar <simar@linux.com>
Co-authored-by: simar7 <1254783+simar7@users.noreply.github.com>
This commit is contained in:
Nikita Pivkin
2024-11-26 01:18:50 +06:00
committed by GitHub
parent 905430337c
commit e9a899a3cf
2 changed files with 78 additions and 4 deletions

View File

@@ -2010,6 +2010,27 @@ variable "baz" {}
assert.Contains(t, buf.String(), "variables=\"foo\"")
}
func TestLogParseErrors(t *testing.T) {
var buf bytes.Buffer
slog.SetDefault(slog.New(log.NewHandler(&buf, nil)))
src := `resource "aws-s3-bucket" "name" {
bucket = <
}`
fsys := fstest.MapFS{
"main.tf": &fstest.MapFile{
Data: []byte(src),
},
}
parser := New(fsys, "")
err := parser.ParseFS(context.TODO(), ".")
require.NoError(t, err)
assert.Contains(t, buf.String(), `cause=" bucket = <"`)
}
func Test_PassingNullToChildModule_DoesNotEraseType(t *testing.T) {
tests := []struct {
name string