fix(feishu): tolerate partial wiki node listing failures

This commit is contained in:
wolfkill
2026-05-12 17:27:42 +08:00
committed by lyingbug
parent 8b2a36d759
commit b387f3637a
3 changed files with 266 additions and 13 deletions
+36 -9
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"sync"
"time"
@@ -27,6 +28,26 @@ type Client struct {
tokenExpAt time.Time
}
type wikiNodeListFailure struct {
Node wikiNode
Err error
}
type partialWikiNodeListError struct {
Failures []wikiNodeListFailure
}
func (e *partialWikiNodeListError) Error() string {
if e == nil || len(e.Failures) == 0 {
return "partial wiki node listing failed"
}
parts := make([]string, 0, len(e.Failures))
for _, failure := range e.Failures {
parts = append(parts, failure.Err.Error())
}
return strings.Join(parts, "; ")
}
// NewClient creates a new Feishu API client.
func NewClient(config *Config) *Client {
return &Client{
@@ -237,9 +258,10 @@ func (c *Client) ListAllWikiNodesRecursive(ctx context.Context, spaceID string)
}
var allNodes []wikiNode
var walk func(nodes []wikiNode) error
var failures []wikiNodeListFailure
var walk func(nodes []wikiNode)
walk = func(nodes []wikiNode) error {
walk = func(nodes []wikiNode) {
for _, node := range nodes {
allNodes = append(allNodes, node)
@@ -247,18 +269,23 @@ func (c *Client) ListAllWikiNodesRecursive(ctx context.Context, spaceID string)
if node.HasChild {
children, err := c.ListWikiNodes(ctx, spaceID, node.NodeToken)
if err != nil {
return fmt.Errorf("list children of %s: %w", node.NodeToken, err)
}
if err := walk(children); err != nil {
return err
wrappedErr := fmt.Errorf("list children of %s: %w", node.NodeToken, err)
failures = append(failures, wikiNodeListFailure{
Node: node,
Err: wrappedErr,
})
logger.Warnf(ctx, "[Feishu] partial wiki node listing failure: space=%s node=%s err=%v",
spaceID, node.NodeToken, err)
continue
}
walk(children)
}
}
return nil
}
if err := walk(topNodes); err != nil {
return nil, err
walk(topNodes)
if len(failures) > 0 {
return allNodes, &partialWikiNodeListError{Failures: failures}
}
return allNodes, nil