dmitri.shuralyov.com/app/changes/...

Handle highlightDiff error by falling back to plain diff.

In case the highlighting algorithm encounters an error on some diff,
we don't want to abort entirely. Fall back to showing plain diff and
log the error for investigation.

This is an intermediate solution until the highlighting algorithm is
improved to handle the problematic case (which may take longer).

Helps https://dmitri.shuralyov.com/app/changes/...$issues/2.
dmitshur committed 6 years ago commit dd0315342c18de7e2450caee433d93b1f4a040ea
Collapse all
display.go
@@ -2,10 +2,11 @@ package changes

import (
	"bytes"
	"fmt"
	"html/template"
	"log"
	"sort"
	"strings"
	"time"

	"dmitri.shuralyov.com/app/changes/component"
@@ -196,15 +197,18 @@ func (f fileDiff) Title() (template.HTML, error) {
func (f fileDiff) Diff() (template.HTML, error) {
	hunks, err := diff.PrintHunks(f.Hunks)
	if err != nil {
		return "", err
	}
	diff, err := highlightDiff(hunks)
	html, err := highlightDiff(hunks)
	if err != nil {
		return "", err
		log.Println("fileDiff.Diff: highlightDiff:", err)
		var buf bytes.Buffer
		template.HTMLEscape(&buf, hunks)
		html = buf.Bytes()
	}
	return template.HTML(diff), nil
	return template.HTML(html), nil
}

// highlightDiff highlights the src diff, returning the annotated HTML.
func highlightDiff(src []byte) ([]byte, error) {
	anns, err := highlight_diff.Annotate(src)