aboutsummaryrefslogtreecommitdiffstats
path: root/core/object.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-16 03:28:21 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-16 03:28:21 -0800
commite82d4918b403a641a5295b3f199586b0ab26b15c (patch)
tree7b16fa8616393ed911824ff5155f40f1b9c38716 /core/object.go
parent45478768e1fa49030b574aec13390fb2d9479836 (diff)
downloadgo-git-e82d4918b403a641a5295b3f199586b0ab26b15c.tar.gz
Functions in core.ObjectStorage interface now return an error
Diffstat (limited to 'core/object.go')
-rw-r--r--core/object.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/core/object.go b/core/object.go
index 62cb469..2f3b262 100644
--- a/core/object.go
+++ b/core/object.go
@@ -23,9 +23,9 @@ type Object interface {
// ObjectStorage generic storage of objects
type ObjectStorage interface {
- New() Object
- Set(Object) Hash
- Get(Hash) (Object, bool)
+ New() (Object, error)
+ Set(Object) (Hash, error)
+ Get(Hash) (Object, error)
Iter(ObjectType) ObjectIter
}
@@ -101,14 +101,11 @@ func (iter *ObjectLookupIter) Next() (Object, error) {
return nil, io.EOF
}
hash := iter.series[iter.pos]
- obj, ok := iter.storage.Get(hash)
- if !ok {
- // FIXME: Consider making ObjectStorage.Get return an actual error that we
- // could pass back here.
- return nil, ObjectNotFoundErr
+ obj, err := iter.storage.Get(hash)
+ if err == nil {
+ iter.pos++
}
- iter.pos++
- return obj, nil
+ return obj, err
}
// Close releases any resources used by the iterator.
@@ -184,11 +181,11 @@ func NewRAWObjectStorage() *RAWObjectStorage {
}
}
-func (o *RAWObjectStorage) New() Object {
- return &RAWObject{}
+func (o *RAWObjectStorage) New() (Object, error) {
+ return &RAWObject{}, nil
}
-func (o *RAWObjectStorage) Set(obj Object) Hash {
+func (o *RAWObjectStorage) Set(obj Object) (Hash, error) {
h := obj.Hash()
o.Objects[h] = obj
@@ -201,13 +198,16 @@ func (o *RAWObjectStorage) Set(obj Object) Hash {
o.Blobs[h] = o.Objects[h]
}
- return h
+ return h, nil
}
-func (o *RAWObjectStorage) Get(h Hash) (Object, bool) {
+func (o *RAWObjectStorage) Get(h Hash) (Object, error) {
obj, ok := o.Objects[h]
+ if !ok {
+ return nil, ObjectNotFoundErr
+ }
- return obj, ok
+ return obj, nil
}
func (o *RAWObjectStorage) Iter(t ObjectType) ObjectIter {