From 5d7b38cabf11c3ec3b781ccf73c5e8d9c92c377b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 1 Sep 2016 22:08:45 +0200 Subject: [PATCH] Remove sentinel errors --- src/restic/tree.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/restic/tree.go b/src/restic/tree.go index 604fac39c..94e51b322 100644 --- a/src/restic/tree.go +++ b/src/restic/tree.go @@ -9,15 +9,12 @@ import ( "restic/debug" ) +// Tree is an ordered list of nodes. type Tree struct { Nodes []*Node `json:"nodes"` } -var ( - ErrNodeNotFound = errors.New("named node not found") - ErrNodeAlreadyInTree = errors.New("node already present") -) - +// NewTree creates a new tree object. func NewTree() *Tree { return &Tree{ Nodes: []*Node{}, @@ -61,10 +58,11 @@ func (t Tree) Equals(other *Tree) bool { return true } +// Insert adds a new node at the correct place in the tree. func (t *Tree) Insert(node *Node) error { pos, _, err := t.binarySearch(node.Name) if err == nil { - return ErrNodeAlreadyInTree + return errors.New("node already present") } // https://code.google.com/p/go-wiki/wiki/SliceTricks @@ -84,7 +82,7 @@ func (t Tree) binarySearch(name string) (int, *Node, error) { return pos, t.Nodes[pos], nil } - return pos, nil, ErrNodeNotFound + return pos, nil, errors.New("named node not found") } func (t Tree) Find(name string) (*Node, error) {