FormatErrorWithContextAt creates a structured error for the given code and location, attaches the SQL context window, and auto-generates a hint. It then returns the fully-formatted error string. This is useful for one-shot error formatting without retaining the *Error value. Parameters: - code: Err
(code ErrorCode, message string, location models.Location, sql string, highlightLen int)
| 55 | // |
| 56 | // Returns the complete formatted error string including context highlighting. |
| 57 | func FormatErrorWithContextAt(code ErrorCode, message string, location models.Location, sql string, highlightLen int) string { |
| 58 | err := NewError(code, message, location) |
| 59 | err = err.WithContext(sql, highlightLen) |
| 60 | |
| 61 | // Auto-generate hints |
| 62 | if hint := GenerateHint(code, "", ""); hint != "" { |
| 63 | err = err.WithHint(hint) |
| 64 | } |
| 65 | |
| 66 | return err.Error() |
| 67 | } |
| 68 | |
| 69 | // FormatMultiLineContext formats an SQL context window around a specific error location. |
| 70 | // It shows up to three lines: one before the error, the error line itself, and one |