From ff809118743100300c38d0c626ffe8c840fb1275 Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Fri, 26 Feb 2016 13:56:39 -0800 Subject: Added function to check validity of core.ObjectType --- core/object.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'core') diff --git a/core/object.go b/core/object.go index d56a44a..7cc8af9 100644 --- a/core/object.go +++ b/core/object.go @@ -79,6 +79,11 @@ func (t ObjectType) Bytes() []byte { return []byte(t.String()) } +// Valid returns true if t is a valid ObjectType. +func (t ObjectType) Valid() bool { + return t >= CommitObject && t <= REFDeltaObject +} + // ParseObjectType parses a string representation of ObjectType. It returns an // error on parse failure. func ParseObjectType(value string) (typ ObjectType, err error) { -- cgit From 31f920a06aa5d7e7cf363645dac02f6e798fffb1 Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Sat, 27 Feb 2016 14:07:22 -0800 Subject: Improved objfile error handling and test coverage --- core/object.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/object.go b/core/object.go index 7cc8af9..9958570 100644 --- a/core/object.go +++ b/core/object.go @@ -8,6 +8,8 @@ import ( var ( ObjectNotFoundErr = errors.New("object not found") + // ErrInvalidType is returned when an invalid object type is provided. + ErrInvalidType = errors.New("invalid object type") ) // TODO: Consider adding a Hash function to the ObjectReader and ObjectWriter @@ -101,7 +103,7 @@ func ParseObjectType(value string) (typ ObjectType, err error) { case "ref-delta": typ = REFDeltaObject default: - err = errors.New("unable to parse object type") + err = ErrInvalidType } return } -- cgit