samuel / go-zookeeper

Native ZooKeeper client for Go. This project is no longer maintained. Please use https://github.com/go-zookeeper/zk instead.
BSD 3-Clause "New" or "Revised" License
1.64k stars 672 forks source link

Exists api return true but path does not exist #236

Open aluode99 opened 4 years ago

aluode99 commented 4 years ago

using Exists api return true when non-ErrNoNode occurs.

_, err := c.request(opExists, &existsRequest{Path: path, Watch: false}, res, nil) exists := true if err == ErrNoNode { exists = false err = nil } return exists, &res.Stat, err

jasonjoo2010 commented 4 years ago

We use Get() instead of Exists() because Exists() doesn't work correctly either for us.

jasonjoo2010 commented 4 years ago

And maybe i know the direct reason (not the real reason) is that we cannot do comparison like below in our own logic:

err == ErrNoNode

Instead, we do

err.Error() == ErrNoNode.Error()

Maybe they are not reused correctly inside though there was a error code map in constants.go

ajpetersons commented 4 years ago

You should ignore all other return values in case non-nil error is returned. The exists return value carries no meaning if an error was present