-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors.go
More file actions
50 lines (39 loc) · 1.78 KB
/
errors.go
File metadata and controls
50 lines (39 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package treeview
import (
"errors"
"fmt"
)
var (
// ErrEmptyID is returned when a node is created with an empty ID string,
// which would prevent proper tree construction and lookups.
ErrEmptyID = errors.New("empty node ID")
// ErrTraversalLimit is raised when TraversalCap
// has been exceeded during a build or file-system scan.
ErrTraversalLimit = errors.New("traversal limit exceeded")
// ErrNodeNotFound is returned by lookup helpers when the requested node
// does not exist in the tree.
ErrNodeNotFound = errors.New("node not found in tree")
// ErrCyclicReference is returned when building a tree encounters a cycle
// in parent-child relationships.
ErrCyclicReference = errors.New("cyclic reference detected in tree")
// ErrTreeConstruction is returned when tree building fails at a high level.
ErrTreeConstruction = errors.New("tree construction failed")
// ErrFileSystem is returned when file system operations fail.
ErrFileSystem = errors.New("file system operation failed")
// ErrPathResolution is returned when a path cannot be resolved.
ErrPathResolution = errors.New("path resolution failed")
// ErrDirectoryScan is returned when directory scanning fails.
ErrDirectoryScan = errors.New("directory scan failed")
)
// pathError creates an error that includes path context.
// It's used internally for file system operations where the path is important.
func pathError(sentinel error, path string, cause error) error {
if cause == nil {
return fmt.Errorf("%w: %s", sentinel, path)
}
return fmt.Errorf("%w: %s: %w", sentinel, path, cause)
}
// cyclicReferenceError creates an error for cyclic references with path details.
func cyclicReferenceError(nodeID, parentID string) error {
return fmt.Errorf("%w: node %q -> parent %q", ErrCyclicReference, nodeID, parentID)
}