add NotFoundError to store
authornsz <nsz@port70.net>
Thu, 8 Dec 2011 02:26:48 +0000 (03:26 +0100)
committernsz <nsz@port70.net>
Thu, 8 Dec 2011 02:26:48 +0000 (03:26 +0100)
store/store.go

index 8bdf317..2a6d2f8 100644 (file)
@@ -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) {