Skip to content

Commit 8ea4063

Browse files
committed
Cleanup addRevision error formatting
1 parent 2303c51 commit 8ea4063

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

db/revtree.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,19 @@ func (tree RevTree) findAncestorFromSet(revid string, ancestors []string) string
409409
}
410410

411411
// Records a revision in a RevTree.
412-
func (tree RevTree) addRevision(docid string, info RevInfo) (err error) {
412+
func (tree RevTree) addRevision(docid string, info RevInfo) error {
413413
revid := info.ID
414414
if revid == "" {
415-
err = errors.New(fmt.Sprintf("doc: %v, RevTree addRevision, empty revid is illegal", docid))
416-
return
415+
return fmt.Errorf("doc: %v, RevTree addRevision, empty revid is illegal", docid)
417416
}
418417
if tree.contains(revid) {
419-
err = errors.New(fmt.Sprintf("doc: %v, RevTree addRevision, already contains rev %q", docid, revid))
420-
return
418+
return fmt.Errorf("doc: %v, RevTree addRevision, already contains rev %q", docid, revid)
421419
}
422-
parent := info.Parent
423-
if parent != "" && !tree.contains(parent) {
424-
err = errors.New(fmt.Sprintf("doc: %v, RevTree addRevision, parent id %q is missing", docid, parent))
425-
return
420+
if p := info.Parent; p != "" {
421+
parent, ok := tree[p]
422+
if !ok {
423+
return fmt.Errorf("doc: %v, RevTree addRevision for rev %q, parent id %q is missing", docid, revid, p)
424+
}
426425
}
427426
tree[revid] = &info
428427
return nil

db/revtree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func TestRevTreeAddRevisionWithMissingParent(t *testing.T) {
333333
assert.Equal(t, testmap, tempmap)
334334

335335
err := tempmap.addRevision("testdoc", RevInfo{ID: "5-five", Parent: "4-four"})
336-
assert.Equal(t, fmt.Sprintf("doc: %v, RevTree addRevision, parent id %q is missing", "testdoc", "4-four"), err.Error())
336+
assert.Equal(t, fmt.Sprintf("doc: %v, RevTree addRevision for rev %q, parent id %q is missing", "testdoc", "5-five", "4-four"), err.Error())
337337
}
338338

339339
func TestRevTreeCompareRevIDs(t *testing.T) {

0 commit comments

Comments
 (0)