Skip to content

Commit 06e23b9

Browse files
committed
feat: add backend part to support sections (#577)
1 parent c8b8f0d commit 06e23b9

File tree

16 files changed

+2659
-2360
lines changed

16 files changed

+2659
-2360
lines changed

internal/core/tree/errors.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package tree
22

3-
import "errors"
3+
import (
4+
"errors"
5+
"fmt"
6+
)
47

58
var ErrPageNotFound = errors.New("page not found")
69
var ErrParentNotFound = errors.New("parent not found")
@@ -12,3 +15,69 @@ var ErrPageCannotBeMovedToItself = errors.New("page cannot be moved to itself")
1215
var ErrInvalidSortOrder = errors.New("invalid sort order")
1316
var ErrFrontmatterParse = errors.New("frontmatter parse error")
1417
var ErrFileNotFound = errors.New("file not found")
18+
var ErrDrift = errors.New("drift detected")
19+
var ErrInvalidOperation = errors.New("invalid operation")
20+
var ErrConvertNotAllowed = errors.New("convert not allowed")
21+
22+
// DriftError represents a drift error with detailed information.
23+
type DriftError struct {
24+
NodeID string
25+
Kind NodeKind
26+
Path string
27+
Reason string
28+
}
29+
30+
func (e *DriftError) Error() string {
31+
return "drift detected: nodeID=" + e.NodeID + ", kind=" + string(e.Kind) + ", path=" + e.Path + ", reason=" + e.Reason
32+
}
33+
34+
func (e *DriftError) Unwrap() error {
35+
return ErrDrift
36+
}
37+
38+
// InvalidOpError represents an invalid operation error with details.
39+
type InvalidOpError struct {
40+
Op string
41+
Reason string
42+
}
43+
44+
func (e *InvalidOpError) Error() string { return fmt.Sprintf("%s: %s", e.Op, e.Reason) }
45+
func (e *InvalidOpError) Unwrap() error { return ErrInvalidOperation }
46+
47+
// PageAlreadyExistsError: Konflikt bei Create/Move/Rename
48+
type PageAlreadyExistsError struct {
49+
Path string
50+
}
51+
52+
func (e *PageAlreadyExistsError) Error() string { return fmt.Sprintf("already exists: %s", e.Path) }
53+
func (e *PageAlreadyExistsError) Unwrap() error { return ErrPageAlreadyExists }
54+
55+
// NotFoundError represents a not found error with details.
56+
type NotFoundError struct {
57+
Resource string
58+
ID string
59+
Path string
60+
}
61+
62+
func (e *NotFoundError) Error() string {
63+
return fmt.Sprintf("%s not found: %s", e.Resource, e.ID)
64+
}
65+
66+
func (e *NotFoundError) Unwrap() error {
67+
return ErrPageNotFound
68+
}
69+
70+
// ConvertNotAllowedError represents a convert not allowed error with details.
71+
type ConvertNotAllowedError struct {
72+
From NodeKind
73+
To NodeKind
74+
Reason string
75+
}
76+
77+
func (e *ConvertNotAllowedError) Error() string {
78+
return fmt.Sprintf("cannot convert from %s to %s: %s", e.From, e.To, e.Reason)
79+
}
80+
81+
func (e *ConvertNotAllowedError) Unwrap() error {
82+
return ErrConvertNotAllowed
83+
}

0 commit comments

Comments
 (0)