Repository: ariga/atlas (go)

Issue:
DDL parser error is obsure when "table" is misspelled
There was a small typo in the schema that the parser did not capture / figure out correctly. I believe there needs to be a better error message in these scenarios:

This was the buggy error DDL

```
tbale "enquries_customers_omlink" {
  schema = schema.application
  comment = "links the one many relationships between the enquiries and customers"

  column "id" {
    type = bigserial
  }

  column customer_id {
    null = false
    type = bigint
  }

  column enquiry_id {
    null = false
    type = bigint
  }

  primary_key {
    columns = [column.id]
  }

  foreign_key "enquiries_customers_omlink_customer_id_fkey" {
    columns = [column.customer_id]
    ref_columns = [table.customers.column.id]
  }

  foreign_key "enquiries_customers_omlink_enquiry_id_fkey" {
    columns = [column.enquiry_id]
    ref_columns = [table.enquiries.column.id]
  }

}
```

Which in turn gives us an obscure error:

```
Error: schema-application.hcl:296,12-21: Unknown variable; There is no variable named "bigserial".
```

I believe we need to update this such that the errors we are seeing is giving us the parent object / its type, etc.



Pull request description:
schemahcl: append validation error on resource error
Closed #3506 

Patch:
diff --git a/schemahcl/schemahcl.go b/schemahcl/schemahcl.go
index b493f087..6c6ffec7 100644
--- a/schemahcl/schemahcl.go
+++ b/schemahcl/schemahcl.go
@@ -7,6 +7,7 @@ package schemahcl
 import (
 	"bytes"
 	"context"
+	"errors"
 	"fmt"
 	"reflect"
 	"slices"
@@ -438,7 +439,7 @@ func (s *State) EvalOptions(parsed *hclparse.Parser, v any, opts *EvalOptions) e
 		file := files[name]
 		r, err := s.resource(ctx, opts, file, reg)
 		if err != nil {
-			return err
+			return errors.Join(vr.Err(), err)
 		}
 		spec.Children = append(spec.Children, r.Children...)
 		spec.Attrs = append(spec.Attrs, r.Attrs...)


Test patch:
diff --git a/schemahcl/schemahcl_test.go b/schemahcl/schemahcl_test.go
index 5b083a65..c24f35ec 100644
--- a/schemahcl/schemahcl_test.go
+++ b/schemahcl/schemahcl_test.go
@@ -1020,6 +1020,39 @@ attr2 = "b"
 	require.NoError(t, err)
 	require.Equal(t, 3, cv.nb)
 	require.Equal(t, 2, cv.na)
+
+}
+
+type errValidator struct{ err error }
+
+func (e *errValidator) Err() error { return e.err }
+func (*errValidator) ValidateBody(*hcl.EvalContext, *hclsyntax.Body) (func() error, error) {
+	return func() error { return nil }, nil
+}
+func (*errValidator) ValidateBlock(*hcl.EvalContext, *hclsyntax.Block) (func() error, error) {
+	return func() error { return nil }, nil
+}
+func (*errValidator) ValidateAttribute(*hcl.EvalContext, *hclsyntax.Attribute, cty.Value) error {
+	return nil
+}
+
+func TestSchemaValidator_Err(t *testing.T) {
+	var (
+		ev = &errValidator{
+			err: fmt.Errorf("validation error"),
+		}
+		doc struct {
+			DefaultExtension
+		}
+	)
+	err := New(
+		WithSchemaValidator(func() SchemaValidator {
+			return ev
+		}),
+	).EvalBytes([]byte(`
+hello = world
+`), &doc, nil)
+	require.EqualError(t, err, "validation error\n:2,9-14: Unknown variable; There is no variable named \"world\".")
 }
 
 func Test_ExtraReferences(t *testing.T) {