Skip to content

Commit edcc8d1

Browse files
committed
chore: add documentation for errors
1 parent 160a7eb commit edcc8d1

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

errors.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,94 @@ package kubernetes
22

33
import "fmt"
44

5+
// ErrNotFound is returned when a requested path key or array index does not exist
6+
// in a NamedObject. This error is used during path traversal operations when:
7+
// - A map key is not present in the object
8+
// - An array index is out of bounds
9+
// - A traversal operation ("-") finds no matching elements
10+
// - A MatchFunc returns false, indicating no match was found
11+
//
12+
// The error string contains the key or index that was not found.
513
type ErrNotFound string
614

715
func (e ErrNotFound) Error() string {
816
return fmt.Sprintf("Not found: %s", string(e))
917
}
1018

19+
// ErrNotTraversable is returned when attempting to traverse through a path element
20+
// that cannot be navigated. This occurs when:
21+
// - A nil value is encountered in the traversal path
22+
// - A node is expected to be a map but is not of type map[string]interface{}
23+
// - A node is expected to be a slice but is not of type []interface{}
24+
// - A parent node during mutation is not the expected map or slice type
25+
// - A node is of an unsupported type for traversal (e.g., primitives, structs)
26+
//
27+
// The error string describes what was encountered and why it cannot be traversed.
1128
type ErrNotTraversable string
1229

1330
func (e ErrNotTraversable) Error() string {
1431
return fmt.Sprintf("Not a traversable type: %s", string(e))
1532
}
1633

34+
// ErrMissingArrayTraversal is returned when a path reaches an array but the next
35+
// path segment does not include proper array notation. This occurs when:
36+
// - An array is encountered but the next path element is neither an index (e.g., "0", "1")
37+
// nor a traversal indicator ("-")
38+
// - The path syntax is invalid for array access
39+
//
40+
// Valid array notations are numeric indices or "-" for traversal. The error string
41+
// contains the problematic path key.
1742
type ErrMissingArrayTraversal string
1843

1944
func (e ErrMissingArrayTraversal) Error() string {
2045
return fmt.Sprintf("Array traversal indicator missing: %s", string(e))
2146
}
2247

48+
// ErrNotAnArray is returned when array notation (index or traversal) is used on a
49+
// path element that is not an array. This occurs when:
50+
// - A map/object is encountered but the path uses array syntax (e.g., "key/-" or "key/0")
51+
// - Array notation is applied to a non-slice type
52+
//
53+
// The error string contains the path key where the invalid array notation was used.
2354
type ErrNotAnArray string
2455

2556
func (e ErrNotAnArray) Error() string {
2657
return fmt.Sprintf("Not an array: %s", string(e))
2758
}
2859

60+
// ErrNotKeyValue is returned when a path operation expects a key-value structure
61+
// (map[string]interface{}) but encounters a different type. This error type is defined
62+
// but currently not used in the codebase. It may be reserved for future validation
63+
// of path items that must be key-value objects.
64+
//
65+
// The error string would contain the problematic path item identifier.
2966
type ErrNotKeyValue string
3067

3168
func (e ErrNotKeyValue) Error() string {
3269
return fmt.Sprintf("Path item is not a key/value object: %s", string(e))
3370
}
3471

72+
// ErrIncorrectType is returned when a value retrieved from a path does not match
73+
// the expected type for the operation. This occurs when:
74+
// - GetString is called but the value is not a string
75+
// - GetSection is called but the value is not a map[string]interface{}
76+
// - GetList is called but the value is not a []interface{}
77+
//
78+
// The error string contains the actual type that was encountered (e.g., "int", "bool").
3579
type ErrIncorrectType string
3680

3781
func (e ErrIncorrectType) Error() string {
3882
return fmt.Sprintf("Incorrect type: %s", string(e))
3983
}
4084

85+
// ErrIndexNotation is returned when attempting to use explicit array index notation
86+
// during path extension operations that require dynamic array growth. This occurs when:
87+
// - Trying to create or add elements to an array using index notation (e.g., "0", "1")
88+
// instead of the append notation ("-")
89+
// - The operation would require inserting at a specific index during array creation
90+
//
91+
// Array modification operations must use "-" for appending; explicit indices are not
92+
// supported during path extension.
4193
type ErrIndexNotation string
4294

4395
func (e ErrIndexNotation) Error() string {

0 commit comments

Comments
 (0)