/
panic.go
68 lines (58 loc) · 1.57 KB
/
panic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sync
import (
"fmt"
"os"
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query"
)
type datastore struct {
child ds.Datastore
}
// Wrap shims a datastore such than _any_ operation failing triggers a panic
// This is useful for debugging invariants.
func Wrap(d ds.Datastore) ds.Shim {
return &datastore{child: d}
}
func (d *datastore) Children() []ds.Datastore {
return []ds.Datastore{d.child}
}
func (d *datastore) Put(key ds.Key, value interface{}) error {
err := d.child.Put(key, value)
if err != nil {
fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
panic("panic datastore: Put failed")
}
return nil
}
func (d *datastore) Get(key ds.Key) (interface{}, error) {
val, err := d.child.Get(key)
if err != nil {
fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
panic("panic datastore: Get failed")
}
return val, nil
}
func (d *datastore) Has(key ds.Key) (bool, error) {
e, err := d.child.Has(key)
if err != nil {
fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
panic("panic datastore: Has failed")
}
return e, nil
}
func (d *datastore) Delete(key ds.Key) error {
err := d.child.Delete(key)
if err != nil {
fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
panic("panic datastore: Delete failed")
}
return nil
}
func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
r, err := d.child.Query(q)
if err != nil {
fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
panic("panic datastore: Query failed")
}
return r, nil
}