Skip to content

Commit 405299d

Browse files
committed
add errors.WithStack to keeper.go
Signed-off-by: Slach <[email protected]>
1 parent fd33e47 commit 405299d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/keeper/keeper.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (k *Keeper) Connect(ctx context.Context, ch *clickhouse.ClickHouse) error {
6767
k.doc = doc
6868
zookeeperNode := xmlquery.FindOne(doc, "//zookeeper")
6969
if zookeeperNode == nil {
70-
return fmt.Errorf("no /zookeeper in %s", configFile)
70+
return errors.WithStack(fmt.Errorf("no /zookeeper in %s", configFile))
7171
}
7272
sessionTimeout := 15 * time.Second
7373
if sessionTimeoutMsNode := zookeeperNode.SelectElement("session_timeout_ms"); sessionTimeoutMsNode != nil {
@@ -79,13 +79,13 @@ func (k *Keeper) Connect(ctx context.Context, ch *clickhouse.ClickHouse) error {
7979
}
8080
nodeList := zookeeperNode.SelectElements("node")
8181
if len(nodeList) == 0 {
82-
return fmt.Errorf("/zookeeper/node not exists in %s", configFile)
82+
return errors.WithStack(fmt.Errorf("/zookeeper/node not exists in %s", configFile))
8383
}
8484
keeperHosts := make([]string, len(nodeList))
8585
for i, node := range nodeList {
8686
hostNode := node.SelectElement("host")
8787
if hostNode == nil {
88-
return fmt.Errorf("/zookeeper/node[%d]/host not exists in %s", i, configFile)
88+
return errors.WithStack(fmt.Errorf("/zookeeper/node[%d]/host not exists in %s", i, configFile))
8989
}
9090
port := "2181"
9191
portNode := node.SelectElement("port")
@@ -114,7 +114,7 @@ func (k *Keeper) GetReplicatedAccessPath(userDirectory string) (string, error) {
114114
xPathQuery := fmt.Sprintf("//user_directories/%s/zookeeper_path", userDirectory)
115115
zookeeperPathNode := xmlquery.FindOne(k.doc, xPathQuery)
116116
if zookeeperPathNode == nil {
117-
return "", fmt.Errorf("can't find %s in %s", xPathQuery, k.xmlConfigFile)
117+
return "", errors.WithStack(fmt.Errorf("can't find %s in %s", xPathQuery, k.xmlConfigFile))
118118
}
119119
zookeeperPath := zookeeperPathNode.InnerText()
120120
if zookeeperPath != "/" {
@@ -210,7 +210,7 @@ func (k *Keeper) Restore(dumpFile, prefix string) error {
210210
//convert from old format
211211
nodeString := DumpNodeString{}
212212
if stringUnmarshalErr := json.Unmarshal(binaryData, &nodeString); stringUnmarshalErr != nil {
213-
return fmt.Errorf("k.Restore can't read data binaryErr=%v, stringErr=%v", err, stringUnmarshalErr)
213+
return errors.WithStack(fmt.Errorf("k.Restore can't read data binaryErr=%v, stringErr=%v", err, stringUnmarshalErr))
214214
}
215215
}
216216
node.Path = path.Join(prefix, node.Path)
@@ -228,7 +228,7 @@ func (k *Keeper) Restore(dumpFile, prefix string) error {
228228
}
229229

230230
if err = scanner.Err(); err != nil {
231-
return fmt.Errorf("can't scan %s, error: %s", dumpFile, err)
231+
return errors.WithStack(fmt.Errorf("can't scan %s, error: %s", dumpFile, err))
232232
}
233233
return nil
234234
}
@@ -240,7 +240,7 @@ func (k *Keeper) Walk(prefix, relativePath string, recursive bool, callback Walk
240240
value, stat, err := k.conn.Get(nodePath)
241241
log.Debug().Msgf("k.Walk->get(%s) = %v, err = %v", nodePath, string(value), err)
242242
if err != nil {
243-
return fmt.Errorf("k.Walk->get(%s) = %v, err = %v", nodePath, string(value), err)
243+
return errors.WithStack(fmt.Errorf("k.Walk->get(%s) = %v, err = %v", nodePath, string(value), err))
244244
}
245245
var isDone bool
246246
callbackNode := DumpNode{Path: nodePath, Value: value}
@@ -254,19 +254,19 @@ func (k *Keeper) Walk(prefix, relativePath string, recursive bool, callback Walk
254254
children, _, err := k.conn.Children(path.Join(prefix, relativePath))
255255
log.Debug().Msgf("k.Walk->Children(%s) = %v, err = %v", path.Join(prefix, relativePath), children, err)
256256
if err != nil {
257-
return fmt.Errorf("k.Walk->Children(%s) = %v, err = %v", path.Join(prefix, relativePath), children, err)
257+
return errors.WithStack(fmt.Errorf("k.Walk->Children(%s) = %v, err = %v", path.Join(prefix, relativePath), children, err))
258258
}
259259
for _, childPath := range children {
260260
if childErr := k.Walk(prefix, path.Join(relativePath, childPath), recursive, callback); childErr != nil {
261-
return childErr
261+
return errors.WithStack(childErr)
262262
}
263263
}
264264
}
265265
return nil
266266
}
267267

268268
func (k *Keeper) Delete(nodePath string) error {
269-
return k.conn.Delete(nodePath, -1)
269+
return errors.WithStack(k.conn.Delete(nodePath, -1))
270270
}
271271
func (k *Keeper) Close() {
272272
k.conn.Close()

0 commit comments

Comments
 (0)