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

Function formatSchemaFailureDetail

pkg/parser/schema_compiler.go:489–526  ·  view source on GitHub ↗

formatSchemaFailureDetail builds a single line of schema error detail for one JSONPathInfo. It is called once per failing schema constraint in validateWithSchemaAndLocation, which then joins them into a "Multiple schema validation failures:" message. Because CompilerError.Position only captures the

(pathInfo JSONPathInfo, schemaJSON, frontmatterContent string, frontmatterStart int)

Source from the content-addressed store, hash-verified

487// The old "at '/path' (line N, column M):" prefix is replaced with "'path' (line N, col M):"
488// to remove the schema-jargon "at" keyword and the leading slash.
489func formatSchemaFailureDetail(pathInfo JSONPathInfo, schemaJSON, frontmatterContent string, frontmatterStart int) string {
490 path := pathInfo.Path
491 if path == "" {
492 path = "/"
493 }
494
495 location := LocateJSONPathForPathInfo(frontmatterContent, pathInfo)
496 line := frontmatterStart
497 column := 1
498 if location.Found {
499 line = location.Line + frontmatterStart - 1
500 column = location.Column
501 }
502
503 message := rewriteAdditionalPropertiesError(cleanOneOfMessage(pathInfo.Message))
504 // Strip any "at '/path': " prefix from the message to avoid duplication with the
505 // "'path' (line N, col M):" prefix we prepend below.
506 message = stripAtPathPrefix(message)
507 // Translate schema constraint language (e.g. "minimum: got X, want Y") to plain English.
508 message = translateSchemaConstraintMessage(message)
509 // Append valid-values hint for well-known fields (e.g. permissions scopes).
510 // hintAdded is true when appendKnownFieldValidValuesHint actually augmented the message
511 // (i.e. the path is a known field and the error is an unknown-property error).
512 // When a hint was added we skip generateSchemaBasedSuggestions to avoid repeating the
513 // same valid-values or "Did you mean" content.
514 message, hintAdded := appendKnownFieldValidValuesHint(message, pathInfo.Path)
515 if !hintAdded {
516 suggestions := generateSchemaBasedSuggestions(schemaJSON, pathInfo.Message, pathInfo.Path, frontmatterContent)
517 if suggestions != "" {
518 message = message + ". " + suggestions
519 }
520 }
521 displayPath := strings.TrimPrefix(path, "/")
522 if displayPath == "" {
523 return message
524 }
525 return fmt.Sprintf("'%s' (line %d, col %d): %s", displayPath, line, column, message)
526}