MCPcopy Create free account
hub / github.com/github/gh-aw / validateWithSchemaAndLocation

Function validateWithSchemaAndLocation

pkg/parser/schema_compiler.go:346–370  ·  view source on GitHub ↗

validateWithSchemaAndLocation validates frontmatter against a JSON schema with location information

(frontmatter map[string]any, schemaJSON, context, filePath string)

Source from the content-addressed store, hash-verified

344
345// validateWithSchemaAndLocation validates frontmatter against a JSON schema with location information
346func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, context, filePath string) error {
347 schemaCompilerLog.Printf("Validating with location info: context=%s, file=%s", context, filePath)
348 err := validateWithSchema(frontmatter, schemaJSON, context)
349 if err == nil {
350 return nil
351 }
352
353 errorMsg := err.Error()
354 isJSONSchemaError := strings.Contains(errorMsg, "jsonschema validation failed")
355 if isJSONSchemaError {
356 errorMsg = cleanJSONSchemaErrorMessage(errorMsg)
357 }
358
359 frontmatterCtx := readFrontmatterContext(filePath)
360 if !isJSONSchemaError {
361 return err
362 }
363
364 jsonPaths := ExtractJSONPathFromValidationError(err)
365 schemaCompilerLog.Printf("Extracted %d JSON path(s) from validation error for %s", len(jsonPaths), context)
366 if locationErr := formatJSONSchemaValidationWithLocation(jsonPaths, schemaJSON, filePath, frontmatterCtx); locationErr != nil {
367 return locationErr
368 }
369 return buildFallbackSchemaValidationError(errorMsg, schemaJSON, filePath, frontmatterCtx)
370}
371
372type frontmatterContextData struct {
373 cleanPath string

Calls 8

validateWithSchemaFunction · 0.85
readFrontmatterContextFunction · 0.85
PrintfMethod · 0.45
ErrorMethod · 0.45