Skip to content

Commit b3a4bbf

Browse files
committed
fix: improve XSD validation error messages with detailed diagnostics
Use helium ErrorCollector to capture individual validation errors instead of the generic 'xsd: validation failed' message. Errors now include the line number and specific schema violation details.
1 parent 3c6a755 commit b3a4bbf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/validator/xml.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ func ValidateXSD(b []byte, schemaPath string) (bool, error) {
6868
return false, fmt.Errorf("xml parse error: %w", err)
6969
}
7070

71-
if err := xsd.NewValidator(schema).Validate(ctx, doc); err != nil {
71+
ec := helium.NewErrorCollector(ctx, helium.ErrorLevelNone)
72+
if err := xsd.NewValidator(schema).ErrorHandler(ec).Validate(ctx, doc); err != nil {
73+
var msgs []string
74+
for _, e := range ec.Errors() {
75+
msgs = append(msgs, e.Error())
76+
}
77+
if len(msgs) > 0 {
78+
return false, fmt.Errorf("schema validation failed: %s", strings.Join(msgs, "; "))
79+
}
7280
return false, fmt.Errorf("schema validation failed: %w", err)
7381
}
7482

0 commit comments

Comments
 (0)