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

Function cleanJSONSchemaErrorMessage

pkg/parser/schema_errors.go:42–75  ·  view source on GitHub ↗

cleanJSONSchemaErrorMessage removes unhelpful prefixes from jsonschema validation errors

(errorMsg string)

Source from the content-addressed store, hash-verified

40
41// cleanJSONSchemaErrorMessage removes unhelpful prefixes from jsonschema validation errors
42func cleanJSONSchemaErrorMessage(errorMsg string) string {
43 schemaErrorsLog.Printf("Cleaning JSON schema error message (%d chars)", len(errorMsg))
44 // Split the error message into lines
45 lines := strings.Split(errorMsg, "\n")
46
47 var cleanedLines []string
48 for _, line := range lines {
49 line = strings.TrimSpace(line)
50
51 // Skip the "jsonschema validation failed" line entirely
52 if strings.HasPrefix(line, "jsonschema validation failed") {
53 continue
54 }
55
56 // Remove the unhelpful "- at '': " prefix from error descriptions
57 line = strings.TrimPrefix(line, "- at '': ")
58
59 // Keep non-empty lines that have actual content
60 if line != "" {
61 cleanedLines = append(cleanedLines, line)
62 }
63 }
64
65 // Join the cleaned lines back together
66 result := strings.Join(cleanedLines, "\n")
67
68 // If we have no meaningful content left, return a generic message
69 if strings.TrimSpace(result) == "" {
70 return "schema validation failed"
71 }
72
73 // Apply oneOf cleanup to the full cleaned message
74 return cleanOneOfMessage(result)
75}
76
77// cleanOneOfMessage simplifies 'oneOf failed, none matched' error messages by:
78// 1. Removing "got X, want Y" type-mismatch lines (from the wrong branch of a oneOf)

Callers 2

Calls 2

cleanOneOfMessageFunction · 0.85
PrintfMethod · 0.45

Tested by 1