FormatErrorWithSuggestion creates and formats a structured error that includes a manually provided hint. When suggestion is empty, the function falls back to auto-generating a hint via GenerateHint. This is the preferred formatter when the caller already knows the correct fix. Parameters: - code: E
(code ErrorCode, message string, location models.Location, sql string, highlightLen int, suggestion string)
| 174 | // |
| 175 | // Returns the complete formatted error string. |
| 176 | func FormatErrorWithSuggestion(code ErrorCode, message string, location models.Location, sql string, highlightLen int, suggestion string) string { |
| 177 | err := NewError(code, message, location) |
| 178 | err = err.WithContext(sql, highlightLen) |
| 179 | |
| 180 | if suggestion != "" { |
| 181 | err = err.WithHint(suggestion) |
| 182 | } else { |
| 183 | // Try to auto-generate suggestion |
| 184 | if autoHint := GenerateHint(code, "", ""); autoHint != "" { |
| 185 | err = err.WithHint(autoHint) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return err.Error() |
| 190 | } |
| 191 | |
| 192 | // FormatErrorList formats a slice of structured errors into a numbered list with |
| 193 | // full context for each entry. The output begins with a count line and separates |