mistifyio/go-zfs

Consider returning errors as a struct

mdlayher opened this issue · 1 comments

If an error occurs when running zfs or zpool, and a non-zero exit code is returned, the following fmt.Errorf() statement is used to create an error message:

https://github.com/mistifyio/go-zfs/blob/master/utils.go#L43

To enable better error handling in client code, I propose that this be replaced with a new struct type, and an Error() method on that struct which can generate a string in the same format as the existing one.

This struct could look something like the following:

http://play.golang.org/p/ctPnZgy2UG

I would be happy to submit a PR if you'd like to move in this direction! Thanks for providing this excellent package!

Good idea! glad you liked it enough to leave a comment. Happy to look at a PR.

We are playing with some different approaches here: https://github.com/bakins/zfsd but ultimately, that will use go-zfs as its backend, but that other project allows a little more experimentation.