Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(364)

Unified Diff: state/util.go

Issue 6296064: state: Second approach to improve the error handling. (Closed)
Patch Set: state: Second approach to improve the error handling. Created 12 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/state_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/util.go
=== modified file 'state/util.go'
--- state/util.go 2012-06-06 10:50:44 +0000
+++ state/util.go 2012-06-13 15:20:15 +0000
@@ -237,11 +237,12 @@
// zkRemoveTree recursively removes a zookeeper node and all its
// children. It does not delete "/zookeeper" or the root node itself
// and it does not consider deleting a nonexistent node to be an error.
-func zkRemoveTree(zk *zookeeper.Conn, path string) error {
+func zkRemoveTree(zk *zookeeper.Conn, path string) (err error) {
+ defer errorContextf(&err, "can't clean up data")
// If we try to delete the zookeeper node (for example when
// calling ZkRemoveTree(zk, "/")) we silently ignore it.
if path == "/zookeeper" {
- return nil
+ return
}
// First recursively delete the children.
children, _, err := zk.Children(path)
@@ -249,11 +250,11 @@
if zookeeper.IsError(err, zookeeper.ZNONODE) {
return nil
}
- return err
+ return
}
for _, child := range children {
- if err := zkRemoveTree(zk, pathpkg.Join(path, child)); err != nil {
- return err
+ if err = zkRemoveTree(zk, pathpkg.Join(path, child)); err != nil {
+ return
}
}
// Now delete the path itself unless it's the root node.
@@ -286,3 +287,12 @@
}
return keys
}
+
+// errorContextf prefixes any error stored in err with text formatted
+// according to the format specifier. If err does not contain an error,
+// errorContextf does nothing.
+func errorContextf(err *error, format string, args ...interface{}) {
+ if *err != nil {
+ *err = errors.New(fmt.Sprintf(format, args...) + ": " + (*err).Error())
+ }
+}
« no previous file with comments | « state/state_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b