From 2dba8527a9eff1f9931ccbb25df34dcb618460a7 Mon Sep 17 00:00:00 2001 From: nsz Date: Thu, 8 Dec 2011 03:26:48 +0100 Subject: [PATCH] add NotFoundError to store --- store/store.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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) { -- 2.20.1