Skip to content

Commit

Permalink
difflib: fix error handling in WriteContextDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
pmezard committed Dec 7, 2015
1 parent 017ffa6 commit 7b7f521
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions difflib/difflib.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,13 @@ func WriteContextDiff(writer io.Writer, diff ContextDiff) error {
diffErr = err
}
}
ws := func(s string) error {
ws := func(s string) {
_, err := buf.WriteString(s)
return err
if diffErr == nil && err != nil {
diffErr = err
}
}

if len(diff.Eol) == 0 {
diff.Eol = "\n"
}
Expand Down Expand Up @@ -713,7 +715,7 @@ func WriteContextDiff(writer io.Writer, diff ContextDiff) error {
}

first, last := g[0], g[len(g)-1]
wf("***************" + diff.Eol)
ws("***************" + diff.Eol)

range1 := formatRangeContext(first.I1, last.I2)
wf("*** %s ****%s", range1, diff.Eol)
Expand Down

0 comments on commit 7b7f521

Please sign in to comment.