aboutsummaryrefslogtreecommitdiff
path: root/object/parse.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-06 21:51:58 +0000
committerGravatar Runxi Yu2026-06-06 21:51:58 +0000
commit41e45d38f2d1ec78881f7e0ce778b2f43fed80a2 (patch)
tree85378d19030bbc44e6fd22078a8fe7ac01c055f1 /object/parse.go
parentref: detached -> direct (diff)
signatureNo signature
ref/name, object: Simplify errors
Diffstat (limited to 'object/parse.go')
-rw-r--r--object/parse.go21
1 files changed, 6 insertions, 15 deletions
diff --git a/object/parse.go b/object/parse.go
index 9a7b9068..b488eb49 100644
--- a/object/parse.go
+++ b/object/parse.go
@@ -1,6 +1,7 @@
package object
import (
+ "errors"
"fmt"
"lindenii.org/go/furgit/object/blob"
@@ -10,20 +11,10 @@ import (
"lindenii.org/go/furgit/object/typ"
)
-// SizeMismatchError indicates a mismatch
-// between the size expected from the object header
-// and the size of the object.
-type SizeMismatchError struct {
- Expected uint64
- Got uint64
-}
-
-func (sizeMismatchError SizeMismatchError) Error() string {
- return fmt.Sprintf(
- "object: size mismatch: header says %d bytes, but got %d from body",
- sizeMismatchError.Expected, sizeMismatchError.Got,
- )
-}
+// ErrSizeMismatch indicates a mismatch
+// between the size declared in the object header
+// and the size of the object body.
+var ErrSizeMismatch = errors.New("object: size mismatch")
// ParseWithHeader parses a loose object
// in "type size\x00body" format.
@@ -37,7 +28,7 @@ func ParseWithHeader(raw []byte, objectFormat id.ObjectFormat) (Object, error) {
body := raw[headerLen:]
if uint64(len(body)) != size {
- return nil, SizeMismatchError{Expected: size, Got: uint64(len(body))}
+ return nil, fmt.Errorf("%w: header declares %d bytes, body has %d", ErrSizeMismatch, size, len(body))
}
return ParseWithoutHeader(ty, body, objectFormat)