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

Function FormatYAMLError

pkg/parser/yaml_error.go:139–155  ·  view source on GitHub ↗

FormatYAMLError formats a YAML error with source code context using yaml.FormatError() frontmatterLineOffset is the line number where the frontmatter content begins in the document (1-based) Returns the formatted error string with line numbers adjusted for frontmatter position

(err error, frontmatterLineOffset int, sourceYAML string)

Source from the content-addressed store, hash-verified

137// frontmatterLineOffset is the line number where the frontmatter content begins in the document (1-based)
138// Returns the formatted error string with line numbers adjusted for frontmatter position
139func FormatYAMLError(err error, frontmatterLineOffset int, sourceYAML string) string {
140 yamlErrorLog.Printf("Formatting YAML error with yaml.FormatError(): offset=%d", frontmatterLineOffset)
141
142 // Use goccy/go-yaml's native FormatError for consistent formatting with source context
143 // colored=false to avoid ANSI escape codes, inclSource=true to include source lines
144 formatted := yaml.FormatError(err, false, true)
145
146 // Translate cryptic parser messages to user-friendly descriptions (header line only)
147 formatted = translateYAMLError(formatted)
148
149 // Adjust line numbers in the formatted output to account for frontmatter position
150 if frontmatterLineOffset > 1 {
151 formatted = adjustLineNumbersInFormattedError(formatted, frontmatterLineOffset-1)
152 }
153
154 return formatted
155}
156
157// adjustLineNumbersInFormattedError adjusts line numbers in yaml.FormatError() output
158// by adding the specified offset to all line numbers

Callers 5

TestFormatYAMLErrorFunction · 0.85
parseFrontmatterYAMLFunction · 0.85

Calls 3

translateYAMLErrorFunction · 0.85
PrintfMethod · 0.45

Tested by 3

TestFormatYAMLErrorFunction · 0.68