MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / FormatErrorWithExample

Function FormatErrorWithExample

pkg/errors/formatter.go:234–243  ·  view source on GitHub ↗

FormatErrorWithExample formats an error and appends a side-by-side "Wrong / Correct" example to the hint. This is particularly useful for educational error messages (e.g., in linters or IDEs) where showing the correct pattern helps users learn the expected SQL syntax. Parameters: - code: ErrorCode

(code ErrorCode, message string, location models.Location, sql string, highlightLen int, wrongExample, correctExample string)

Source from the content-addressed store, hash-verified

232//
233// Returns the complete formatted error string including the before/after example.
234func FormatErrorWithExample(code ErrorCode, message string, location models.Location, sql string, highlightLen int, wrongExample, correctExample string) string {
235 err := NewError(code, message, location)
236 err = err.WithContext(sql, highlightLen)
237
238 // Add hint with before/after example
239 hint := fmt.Sprintf("Wrong: %s\nCorrect: %s", wrongExample, correctExample)
240 err = err.WithHint(hint)
241
242 return err.Error()
243}
244
245// FormatContextWindow formats a configurable SQL context window of up to linesBefore
246// lines before and linesAfter lines after the error line. Prefer this over

Callers 1

Calls 4

WithContextMethod · 0.95
WithHintMethod · 0.95
ErrorMethod · 0.95
NewErrorFunction · 0.70

Tested by 1