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)
| 232 | // |
| 233 | // Returns the complete formatted error string including the before/after example. |
| 234 | func 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 |