Bound repair feedback construction
This commit is contained in:
@@ -117,27 +117,38 @@ func repairGuidance(mode domain.ValidationMode) (string, error) {
|
||||
}
|
||||
|
||||
func formatRepairDiagnostics(errors []string) string {
|
||||
diagnostics := make([]string, len(errors))
|
||||
for index, diagnostic := range errors {
|
||||
diagnostics[index] = strings.ToValidUTF8(diagnostic, "\uFFFD")
|
||||
complete := []byte{'['}
|
||||
fits := true
|
||||
for _, diagnostic := range errors {
|
||||
separator := 0
|
||||
if len(complete) > 1 {
|
||||
separator = 1
|
||||
}
|
||||
entry, whole := boundedDiagnosticJSON(diagnostic, maxRepairDiagnosticBytes-len(complete)-separator-1)
|
||||
if !whole {
|
||||
fits = false
|
||||
break
|
||||
}
|
||||
if separator != 0 {
|
||||
complete = append(complete, ',')
|
||||
}
|
||||
complete = append(complete, entry...)
|
||||
}
|
||||
|
||||
complete, _ := json.Marshal(diagnostics)
|
||||
if len(complete) <= maxRepairDiagnosticBytes {
|
||||
return string(complete)
|
||||
if fits {
|
||||
return string(append(complete, ']'))
|
||||
}
|
||||
|
||||
omission, _ := json.Marshal(omittedRepairDiagnostics)
|
||||
encoded := make([]byte, 0, maxRepairDiagnosticBytes)
|
||||
encoded = append(encoded, '[')
|
||||
for _, diagnostic := range diagnostics {
|
||||
entry, _ := json.Marshal(diagnostic)
|
||||
for _, diagnostic := range errors {
|
||||
separator := 0
|
||||
if len(encoded) > 1 {
|
||||
separator = 1
|
||||
}
|
||||
available := maxRepairDiagnosticBytes - len(encoded) - separator - 1 - len(omission) - 1
|
||||
if len(entry) <= available {
|
||||
entry, whole := boundedDiagnosticJSON(diagnostic, available)
|
||||
if whole {
|
||||
if separator != 0 {
|
||||
encoded = append(encoded, ',')
|
||||
}
|
||||
@@ -151,7 +162,7 @@ func formatRepairDiagnostics(errors []string) string {
|
||||
if separator != 0 {
|
||||
encoded = append(encoded, ',')
|
||||
}
|
||||
encoded = append(encoded, truncateDiagnosticJSONValue(diagnostic, available)...)
|
||||
encoded = append(encoded, entry...)
|
||||
break
|
||||
}
|
||||
if len(encoded) > 1 {
|
||||
|
||||
Reference in New Issue
Block a user