From: nsz Date: Thu, 8 Dec 2011 02:26:48 +0000 (+0100) Subject: add NotFoundError to store X-Git-Url: http://nsz.repo.hu/git/?p=epoint;a=commitdiff_plain;h=2dba8527a9eff1f9931ccbb25df34dcb618460a7;hp=34d06eb5c368465927c780c21d6deac1c7f847b8 add NotFoundError to store --- diff --git a/store/store.go b/store/store.go index 8bdf317..2a6d2f8 100644 --- a/store/store.go +++ b/store/store.go @@ -17,6 +17,14 @@ type Conn struct { path string } +type NotFoundError struct { + path string +} + +func (e NotFoundError) Error() string { + return "not found: " + e.path +} + func Open(root string) (c *Conn, err error) { c = new(Conn) c.path, err = filepath.Abs(root) @@ -31,7 +39,13 @@ func Open(root string) (c *Conn, err error) { } func (c *Conn) Get(name, k string) (v []byte, err error) { - return ioutil.ReadFile(filepath.Join(c.path, name, k)) + v, err = ioutil.ReadFile(filepath.Join(c.path, name, k)) + if err != nil { + if p, ok := err.(*os.PathError); ok && p.Err == os.ENOENT { + err = NotFoundError{name+"/"+k} + } + } + return } func (c *Conn) Ensure(name string) (err error) {