ToDisplayString returns the error set to a newline delimited string.
()
| 82 | |
| 83 | // ToDisplayString returns the error set to a newline delimited string. |
| 84 | func (e *Errors) ToDisplayString() string { |
| 85 | errorsInString := e.maxErrorsToReport |
| 86 | if e.numErrors > e.maxErrorsToReport { |
| 87 | // add one more error to indicate the number of errors truncated. |
| 88 | errorsInString++ |
| 89 | } else { |
| 90 | // otherwise the error set will just contain the number of errors. |
| 91 | errorsInString = e.numErrors |
| 92 | } |
| 93 | |
| 94 | result := make([]string, errorsInString) |
| 95 | sort.SliceStable(e.errors, func(i, j int) bool { |
| 96 | ei := e.errors[i].Location |
| 97 | ej := e.errors[j].Location |
| 98 | return ei.Line() < ej.Line() || |
| 99 | (ei.Line() == ej.Line() && ei.Column() < ej.Column()) |
| 100 | }) |
| 101 | for i, err := range e.errors { |
| 102 | // This can happen during the append of two errors objects |
| 103 | if i >= e.maxErrorsToReport { |
| 104 | break |
| 105 | } |
| 106 | result[i] = err.ToDisplayString(e.source) |
| 107 | } |
| 108 | if e.numErrors > e.maxErrorsToReport { |
| 109 | result[e.maxErrorsToReport] = fmt.Sprintf("%d more errors were truncated", e.numErrors-e.maxErrorsToReport) |
| 110 | } |
| 111 | return strings.Join(result, "\n") |
| 112 | } |