From 1ede018ea67df6be89c68078f141227e0e5fb756 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 28 Jul 2020 22:32:57 +0200 Subject: [PATCH] error variable names should start with 'Err' --- cmd/restic/cmd_find.go | 6 +++--- cmd/restic/cmd_ls.go | 2 +- internal/walker/walker.go | 14 +++++++------- internal/walker/walker_test.go | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 68b5947ee..84a709b15 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -270,7 +270,7 @@ func (f *Finder) findInSnapshot(ctx context.Context, sn *restic.Snapshot) error Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID()) - return false, walker.SkipNode + return false, walker.ErrSkipNode } if node == nil { @@ -314,7 +314,7 @@ func (f *Finder) findInSnapshot(ctx context.Context, sn *restic.Snapshot) error if !childMayMatch { ignoreIfNoMatch = true - errIfNoMatch = walker.SkipNode + errIfNoMatch = walker.ErrSkipNode } else { ignoreIfNoMatch = false } @@ -354,7 +354,7 @@ func (f *Finder) findIDs(ctx context.Context, sn *restic.Snapshot) error { Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID()) - return false, walker.SkipNode + return false, walker.ErrSkipNode } if node == nil { diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index dec46a375..0fa21b145 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -222,7 +222,7 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { // otherwise, signal the walker to not walk recursively into any // subdirs if node.Type == "dir" { - return false, walker.SkipNode + return false, walker.ErrSkipNode } return false, nil }) diff --git a/internal/walker/walker.go b/internal/walker/walker.go index 0146b0668..e06343ac3 100644 --- a/internal/walker/walker.go +++ b/internal/walker/walker.go @@ -10,15 +10,15 @@ import ( "github.com/restic/restic/internal/restic" ) -// SkipNode is returned by WalkFunc when a dir node should not be walked. -var SkipNode = errors.New("skip this node") +// ErrSkipNode is returned by WalkFunc when a dir node should not be walked. +var ErrSkipNode = errors.New("skip this node") // WalkFunc is the type of the function called for each node visited by Walk. // Path is the slash-separated path from the root node. If there was a problem // loading a node, err is set to a non-nil error. WalkFunc can chose to ignore // it by returning nil. // -// When the special value SkipNode is returned and node is a dir node, it is +// When the special value ErrSkipNode is returned and node is a dir node, it is // not walked. When the node is not a dir node, the remaining items in this // tree are skipped. // @@ -26,7 +26,7 @@ var SkipNode = errors.New("skip this node") // For tree nodes, this means that the function is not called for the // referenced tree. If the node is not a tree, and all nodes in the current // tree have ignore set to true, the current tree will not be visited again. -// When err is not nil and different from SkipNode, the value returned for +// When err is not nil and different from ErrSkipNode, the value returned for // ignore is ignored. type WalkFunc func(parentTreeID restic.ID, path string, node *restic.Node, nodeErr error) (ignore bool, err error) @@ -38,7 +38,7 @@ func Walk(ctx context.Context, repo restic.TreeLoader, root restic.ID, ignoreTre _, err = walkFn(root, "/", nil, err) if err != nil { - if err == SkipNode { + if err == ErrSkipNode { err = nil } return err @@ -76,7 +76,7 @@ func walk(ctx context.Context, repo restic.TreeLoader, prefix string, parentTree if node.Type != "dir" { ignore, err := walkFn(parentTreeID, p, node, nil) if err != nil { - if err == SkipNode { + if err == ErrSkipNode { // skip the remaining entries in this tree return allNodesIgnored, nil } @@ -102,7 +102,7 @@ func walk(ctx context.Context, repo restic.TreeLoader, prefix string, parentTree subtree, err := repo.LoadTree(ctx, *node.Subtree) ignore, err := walkFn(parentTreeID, p, node, err) if err != nil { - if err == SkipNode { + if err == ErrSkipNode { if ignore { ignoreTrees.Insert(*node.Subtree) } diff --git a/internal/walker/walker_test.go b/internal/walker/walker_test.go index af5c25f42..930c40716 100644 --- a/internal/walker/walker_test.go +++ b/internal/walker/walker_test.go @@ -138,7 +138,7 @@ func checkParentTreeOrder(want []string) checkFunc { } } -// checkSkipFor returns SkipNode if path is in skipFor, it checks that the +// checkSkipFor returns ErrSkipNode if path is in skipFor, it checks that the // paths the walk func is called for are exactly the ones in wantPaths. func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc { var pos int @@ -161,7 +161,7 @@ func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc { pos++ if _, ok := skipFor[path]; ok { - return false, SkipNode + return false, ErrSkipNode } return false, nil @@ -177,7 +177,7 @@ func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc { } } -// checkIgnore returns SkipNode if path is in skipFor and sets ignore according +// checkIgnore returns ErrSkipNode if path is in skipFor and sets ignore according // to ignoreFor. It checks that the paths the walk func is called for are exactly // the ones in wantPaths. func checkIgnore(skipFor map[string]struct{}, ignoreFor map[string]bool, wantPaths []string) checkFunc { @@ -201,7 +201,7 @@ func checkIgnore(skipFor map[string]struct{}, ignoreFor map[string]bool, wantPat pos++ if _, ok := skipFor[path]; ok { - return ignoreFor[path], SkipNode + return ignoreFor[path], ErrSkipNode } return ignoreFor[path], nil