FormatErrorList formats a slice of structured errors into a numbered list with full context for each entry. The output begins with a count line and separates each error with a blank line. Returns "No errors" when the slice is empty. Parameters: - errors: Slice of *Error values to format Returns t
(errors []*Error)
| 200 | // |
| 201 | // Returns the multi-error report string. |
| 202 | func FormatErrorList(errors []*Error) string { |
| 203 | if len(errors) == 0 { |
| 204 | return "No errors" |
| 205 | } |
| 206 | |
| 207 | var sb strings.Builder |
| 208 | sb.WriteString(fmt.Sprintf("Found %d error(s):\n\n", len(errors))) |
| 209 | |
| 210 | for i, err := range errors { |
| 211 | sb.WriteString(fmt.Sprintf("Error %d:\n", i+1)) |
| 212 | sb.WriteString(err.Error()) |
| 213 | sb.WriteString("\n\n") |
| 214 | } |
| 215 | |
| 216 | return sb.String() |
| 217 | } |
| 218 | |
| 219 | // FormatErrorWithExample formats an error and appends a side-by-side "Wrong / Correct" |
| 220 | // example to the hint. This is particularly useful for educational error messages |