diff options
| author | 2026-03-06 18:38:44 +0800 | |
|---|---|---|
| committer | 2026-03-06 18:58:30 +0800 | |
| commit | f2922155de01b734e3e8b3f50be8f263ec13cacd (patch) | |
| tree | 6dcfcf5689e63eea09314dce543e1de26cab89fe /format | |
| parent | internal/compress: Format (diff) | |
| signature | No signature | |
*: Lint v0.1.68
Diffstat (limited to 'format')
29 files changed, 137 insertions, 143 deletions
diff --git a/format/commitgraph/read/bloom.go b/format/commitgraph/read/bloom.go index 9b66f458..e00b800f 100644 --- a/format/commitgraph/read/bloom.go +++ b/format/commitgraph/read/bloom.go @@ -38,7 +38,7 @@ func (reader *Reader) BloomVersion() uint8 { // BloomFilterAt returns one commit's changed-path Bloom filter. // -// Returns ErrBloomUnavailable when this commit graph has no Bloom data. +// Returns BloomUnavailableError when this commit graph has no Bloom data. func (reader *Reader) BloomFilterAt(pos Position) (*bloom.Filter, error) { layer, err := reader.layerByPosition(pos) if err != nil { @@ -46,7 +46,7 @@ func (reader *Reader) BloomFilterAt(pos Position) (*bloom.Filter, error) { } if layer.chunkBloomIndex == nil || layer.chunkBloomData == nil || layer.bloomSettings == nil { - return nil, &ErrBloomUnavailable{Pos: pos} + return nil, &BloomUnavailableError{Pos: pos} } start, end, err := bloomRange(layer, pos.Index) @@ -86,7 +86,7 @@ func bloomRange(layer *layer, commitIndex uint32) (int, int, error) { } if end < start { - return 0, 0, &ErrMalformed{Path: layer.path, Reason: "invalid BIDX range"} + return 0, 0, &MalformedError{Path: layer.path, Reason: "invalid BIDX range"} } bdatLen := len(layer.chunkBloomData) - bloom.DataHeaderSize @@ -97,7 +97,7 @@ func bloomRange(layer *layer, commitIndex uint32) (int, int, error) { } if end > bdatLenU32 { - return 0, 0, &ErrMalformed{Path: layer.path, Reason: "BIDX range out of BDAT bounds"} + return 0, 0, &MalformedError{Path: layer.path, Reason: "BIDX range out of BDAT bounds"} } startInt, err := intconv.Uint64ToInt(uint64(start)) diff --git a/format/commitgraph/read/edges.go b/format/commitgraph/read/edges.go index de8bab60..96ffeb6d 100644 --- a/format/commitgraph/read/edges.go +++ b/format/commitgraph/read/edges.go @@ -9,7 +9,7 @@ import ( func (reader *Reader) decodeExtraEdgeList(layer *layer, edgeStart uint32) ([]Position, error) { if len(layer.chunkExtraEdges) == 0 { - return nil, &ErrMalformed{Path: layer.path, Reason: "missing EDGE chunk"} + return nil, &MalformedError{Path: layer.path, Reason: "missing EDGE chunk"} } out := make([]Position, 0) @@ -24,7 +24,7 @@ func (reader *Reader) decodeExtraEdgeList(layer *layer, edgeStart uint32) ([]Pos } if off+4 > len(layer.chunkExtraEdges) { - return nil, &ErrMalformed{Path: layer.path, Reason: "EDGE index out of range"} + return nil, &MalformedError{Path: layer.path, Reason: "EDGE index out of range"} } word := binary.BigEndian.Uint32(layer.chunkExtraEdges[off : off+4]) diff --git a/format/commitgraph/read/errors.go b/format/commitgraph/read/errors.go index 9d0eca04..8dd02a60 100644 --- a/format/commitgraph/read/errors.go +++ b/format/commitgraph/read/errors.go @@ -6,53 +6,53 @@ import ( "codeberg.org/lindenii/furgit/objectid" ) -// ErrNotFound reports a missing commit graph entry by object ID. -type ErrNotFound struct { +// NotFoundError reports a missing commit graph entry by object ID. +type NotFoundError struct { OID objectid.ObjectID } // Error implements error. -func (err *ErrNotFound) Error() string { +func (err *NotFoundError) Error() string { return fmt.Sprintf("format/commitgraph: object not found: %s", err.OID) } -// ErrPositionOutOfRange reports an invalid graph position. -type ErrPositionOutOfRange struct { +// PositionOutOfRangeError reports an invalid graph position. +type PositionOutOfRangeError struct { Pos Position } // Error implements error. -func (err *ErrPositionOutOfRange) Error() string { +func (err *PositionOutOfRangeError) Error() string { return fmt.Sprintf("format/commitgraph: position out of range: graph=%d index=%d", err.Pos.Graph, err.Pos.Index) } -// ErrMalformed reports malformed commit-graph data. -type ErrMalformed struct { +// MalformedError reports malformed commit-graph data. +type MalformedError struct { Path string Reason string } // Error implements error. -func (err *ErrMalformed) Error() string { +func (err *MalformedError) Error() string { return fmt.Sprintf("format/commitgraph: malformed %q: %s", err.Path, err.Reason) } -// ErrUnsupportedVersion reports unsupported commit-graph version. -type ErrUnsupportedVersion struct { +// UnsupportedVersionError reports unsupported commit-graph version. +type UnsupportedVersionError struct { Version uint8 } // Error implements error. -func (err *ErrUnsupportedVersion) Error() string { +func (err *UnsupportedVersionError) Error() string { return fmt.Sprintf("format/commitgraph: unsupported version %d", err.Version) } -// ErrBloomUnavailable reports missing changed-path bloom data at one position. -type ErrBloomUnavailable struct { +// BloomUnavailableError reports missing changed-path bloom data at one position. +type BloomUnavailableError struct { Pos Position } // Error implements error. -func (err *ErrBloomUnavailable) Error() string { +func (err *BloomUnavailableError) Error() string { return fmt.Sprintf("format/commitgraph: bloom unavailable at position graph=%d index=%d", err.Pos.Graph, err.Pos.Index) } diff --git a/format/commitgraph/read/generation.go b/format/commitgraph/read/generation.go index d1f0ebe7..62e47996 100644 --- a/format/commitgraph/read/generation.go +++ b/format/commitgraph/read/generation.go @@ -34,7 +34,7 @@ func (reader *Reader) readGenerationV2(layer *layer, index uint32, commitTime ui } if gdo2Off+8 > len(layer.chunkGenerationOv) { - return 0, &ErrMalformed{Path: layer.path, Reason: "GDO2 index out of range"} + return 0, &MalformedError{Path: layer.path, Reason: "GDO2 index out of range"} } overflow := binary.BigEndian.Uint64(layer.chunkGenerationOv[gdo2Off : gdo2Off+8]) diff --git a/format/commitgraph/read/hash.go b/format/commitgraph/read/hash.go index 3f30df91..e9543eac 100644 --- a/format/commitgraph/read/hash.go +++ b/format/commitgraph/read/hash.go @@ -16,7 +16,7 @@ func (reader *Reader) HashVersion() uint8 { func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, graph *layer) error { if idx == 0 { if len(graph.chunkBaseGraphs) != 0 { - return &ErrMalformed{Path: graph.path, Reason: "unexpected BASE chunk in first graph"} + return &MalformedError{Path: graph.path, Reason: "unexpected BASE chunk in first graph"} } return nil @@ -26,7 +26,7 @@ func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, g expectedLen := idx * hashSize if len(graph.chunkBaseGraphs) != expectedLen { - return &ErrMalformed{ + return &MalformedError{ Path: graph.path, Reason: fmt.Sprintf("BASE chunk length %d does not match expected %d", len(graph.chunkBaseGraphs), expectedLen), } @@ -42,7 +42,7 @@ func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, g } if baseHash.String() != chain[i] { - return &ErrMalformed{ + return &MalformedError{ Path: graph.path, Reason: fmt.Sprintf("BASE chunk mismatch at index %d", i), } @@ -55,7 +55,7 @@ func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, g func verifyTrailerHash(data []byte, algo objectid.Algorithm, path string) error { hashSize := algo.Size() if len(data) < hashSize { - return &ErrMalformed{Path: path, Reason: "file too short for trailer"} + return &MalformedError{Path: path, Reason: "file too short for trailer"} } hashImpl, err := algo.New() @@ -72,7 +72,7 @@ func verifyTrailerHash(data []byte, algo objectid.Algorithm, path string) error want := data[len(data)-hashSize:] if !bytes.Equal(got, want) { - return &ErrMalformed{Path: path, Reason: "trailer hash mismatch"} + return &MalformedError{Path: path, Reason: "trailer hash mismatch"} } return nil diff --git a/format/commitgraph/read/layer_open.go b/format/commitgraph/read/layer_open.go index bf126960..1190108e 100644 --- a/format/commitgraph/read/layer_open.go +++ b/format/commitgraph/read/layer_open.go @@ -26,7 +26,7 @@ func openLayer(root *os.Root, relPath string, algo objectid.Algorithm) (*layer, if size < int64(commitgraph.HeaderSize+commitgraph.FanoutSize+algo.Size()) { _ = file.Close() - return nil, &ErrMalformed{Path: relPath, Reason: "file too short"} + return nil, &MalformedError{Path: relPath, Reason: "file too short"} } mapLen, err := intconv.Int64ToUint64(size) diff --git a/format/commitgraph/read/layer_parse.go b/format/commitgraph/read/layer_parse.go index dca9f416..b615010f 100644 --- a/format/commitgraph/read/layer_parse.go +++ b/format/commitgraph/read/layer_parse.go @@ -11,19 +11,19 @@ import ( func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx if len(layer.data) < commitgraph.HeaderSize { - return &ErrMalformed{Path: layer.path, Reason: "file too short"} + return &MalformedError{Path: layer.path, Reason: "file too short"} } header := layer.data[:commitgraph.HeaderSize] signature := binary.BigEndian.Uint32(header[:4]) if signature != commitgraph.FileSignature { - return &ErrMalformed{Path: layer.path, Reason: "invalid signature"} + return &MalformedError{Path: layer.path, Reason: "invalid signature"} } version := header[4] if version != commitgraph.FileVersion { - return &ErrUnsupportedVersion{Version: version} + return &UnsupportedVersionError{Version: version} } expectedHashVersion, err := intconv.Uint32ToUint8(algo.PackHashID()) @@ -33,7 +33,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx hashVersion := header[5] if hashVersion != expectedHashVersion { - return &ErrMalformed{Path: layer.path, Reason: "hash version does not match object format"} + return &MalformedError{Path: layer.path, Reason: "hash version does not match object format"} } numChunks := int(header[6]) @@ -44,7 +44,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx tocEnd := tocStart + tocLen if tocEnd > len(layer.data) { - return &ErrMalformed{Path: layer.path, Reason: "truncated chunk table"} + return &MalformedError{Path: layer.path, Reason: "truncated chunk table"} } type tocEntry struct { @@ -65,7 +65,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if entries[len(entries)-1].id != 0 { - return &ErrMalformed{Path: layer.path, Reason: "missing chunk table terminator"} + return &MalformedError{Path: layer.path, Reason: "missing chunk table terminator"} } trailerStart := len(layer.data) - algo.Size() @@ -74,7 +74,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx for i := range numChunks { entry := entries[i] if entry.id == 0 { - return &ErrMalformed{Path: layer.path, Reason: "early chunk table terminator"} + return &MalformedError{Path: layer.path, Reason: "early chunk table terminator"} } next := entries[i+1] @@ -90,11 +90,11 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if start < tocEnd || end < start || end > trailerStart { - return &ErrMalformed{Path: layer.path, Reason: "invalid chunk offsets"} + return &MalformedError{Path: layer.path, Reason: "invalid chunk offsets"} } if _, exists := chunks[entry.id]; exists { - return &ErrMalformed{Path: layer.path, Reason: "duplicate chunk id"} + return &MalformedError{Path: layer.path, Reason: "duplicate chunk id"} } chunks[entry.id] = layer.data[start:end] @@ -102,7 +102,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx oidf := chunks[commitgraph.ChunkOIDF] if len(oidf) != commitgraph.FanoutSize { - return &ErrMalformed{Path: layer.path, Reason: "invalid OIDF length"} + return &MalformedError{Path: layer.path, Reason: "invalid OIDF length"} } layer.chunkOIDFanout = oidf @@ -113,7 +113,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx next := binary.BigEndian.Uint32(oidf[(i+1)*4 : (i+2)*4]) if cur > next { - return &ErrMalformed{Path: layer.path, Reason: "non-monotonic OIDF fanout"} + return &MalformedError{Path: layer.path, Reason: "non-monotonic OIDF fanout"} } } @@ -133,7 +133,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if len(oidl) != oidlWantLen { - return &ErrMalformed{Path: layer.path, Reason: "invalid OIDL length"} + return &MalformedError{Path: layer.path, Reason: "invalid OIDL length"} } layer.chunkOIDLookup = oidl @@ -154,7 +154,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if len(cdat) != cdatWantLen { - return &ErrMalformed{Path: layer.path, Reason: "invalid CDAT length"} + return &MalformedError{Path: layer.path, Reason: "invalid CDAT length"} } layer.chunkCommit = cdat @@ -169,7 +169,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if len(gda2) != wantLen { - return &ErrMalformed{Path: layer.path, Reason: "invalid GDA2 length"} + return &MalformedError{Path: layer.path, Reason: "invalid GDA2 length"} } layer.chunkGeneration = gda2 @@ -178,7 +178,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx gdo2 := chunks[commitgraph.ChunkGDO2] if len(gdo2) != 0 { if len(gdo2)%8 != 0 { - return &ErrMalformed{Path: layer.path, Reason: "invalid GDO2 length"} + return &MalformedError{Path: layer.path, Reason: "invalid GDO2 length"} } layer.chunkGenerationOv = gdo2 @@ -187,7 +187,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx edge := chunks[commitgraph.ChunkEDGE] if len(edge) != 0 { if len(edge)%4 != 0 { - return &ErrMalformed{Path: layer.path, Reason: "invalid EDGE length"} + return &MalformedError{Path: layer.path, Reason: "invalid EDGE length"} } layer.chunkExtraEdges = edge @@ -196,7 +196,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx base := chunks[commitgraph.ChunkBASE] if baseCount == 0 { if len(base) != 0 { - return &ErrMalformed{Path: layer.path, Reason: "unexpected BASE chunk"} + return &MalformedError{Path: layer.path, Reason: "unexpected BASE chunk"} } } else { wantLen64 := uint64(baseCount) * hashSizeU64 @@ -207,7 +207,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if len(base) != wantLen { - return &ErrMalformed{Path: layer.path, Reason: "invalid BASE length"} + return &MalformedError{Path: layer.path, Reason: "invalid BASE length"} } layer.chunkBaseGraphs = base @@ -220,7 +220,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx bdat := chunks[commitgraph.ChunkBDAT] if len(bidx) != 0 || len(bdat) != 0 { //nolint:nestif if len(bidx) == 0 || len(bdat) == 0 { - return &ErrMalformed{Path: layer.path, Reason: "BIDX/BDAT must both be present"} + return &MalformedError{Path: layer.path, Reason: "BIDX/BDAT must both be present"} } bidxWantLen64 := uint64(layer.numCommits) * 4 @@ -231,11 +231,11 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if len(bidx) != bidxWantLen { - return &ErrMalformed{Path: layer.path, Reason: "invalid BIDX length"} + return &MalformedError{Path: layer.path, Reason: "invalid BIDX length"} } if len(bdat) < bloom.DataHeaderSize { - return &ErrMalformed{Path: layer.path, Reason: "invalid BDAT length"} + return &MalformedError{Path: layer.path, Reason: "invalid BDAT length"} } settings, err := bloom.ParseSettings(bdat) @@ -250,7 +250,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx cur := binary.BigEndian.Uint32(bidx[off : off+4]) if i > 0 && cur < prev { - return &ErrMalformed{Path: layer.path, Reason: "non-monotonic BIDX"} + return &MalformedError{Path: layer.path, Reason: "non-monotonic BIDX"} } bdatDataLen := len(bdat) - bloom.DataHeaderSize @@ -261,7 +261,7 @@ func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx } if cur > bdatDataLenU32 { - return &ErrMalformed{Path: layer.path, Reason: "BIDX offset out of range"} + return &MalformedError{Path: layer.path, Reason: "BIDX offset out of range"} } prev = cur diff --git a/format/commitgraph/read/layer_pos.go b/format/commitgraph/read/layer_pos.go index b93a842e..7b87b381 100644 --- a/format/commitgraph/read/layer_pos.go +++ b/format/commitgraph/read/layer_pos.go @@ -9,12 +9,12 @@ func (reader *Reader) layerByPosition(pos Position) (*layer, error) { } if graphIdx < 0 || graphIdx >= len(reader.layers) { - return nil, &ErrPositionOutOfRange{Pos: pos} + return nil, &PositionOutOfRangeError{Pos: pos} } layer := &reader.layers[graphIdx] if pos.Index >= layer.numCommits { - return nil, &ErrPositionOutOfRange{Pos: pos} + return nil, &PositionOutOfRangeError{Pos: pos} } return layer, nil diff --git a/format/commitgraph/read/lookup.go b/format/commitgraph/read/lookup.go index cfd3b8cc..6ba25a18 100644 --- a/format/commitgraph/read/lookup.go +++ b/format/commitgraph/read/lookup.go @@ -8,7 +8,7 @@ import ( // Lookup resolves one object ID to one graph position. func (reader *Reader) Lookup(oid objectid.ObjectID) (Position, error) { if oid.Algorithm() != reader.algo { - return Position{}, &ErrNotFound{OID: oid} + return Position{}, &NotFoundError{OID: oid} } for layerIdx := len(reader.layers) - 1; layerIdx >= 0; layerIdx-- { @@ -25,5 +25,5 @@ func (reader *Reader) Lookup(oid objectid.ObjectID) (Position, error) { } } - return Position{}, &ErrNotFound{OID: oid} + return Position{}, &NotFoundError{OID: oid} } diff --git a/format/commitgraph/read/open_chain.go b/format/commitgraph/read/open_chain.go index f64040bc..8d5ec268 100644 --- a/format/commitgraph/read/open_chain.go +++ b/format/commitgraph/read/open_chain.go @@ -17,7 +17,7 @@ func openChain(root *os.Root, algo objectid.Algorithm) (*Reader, error) { file, err := root.Open(chainPath) if err != nil { if errors.Is(err, os.ErrNotExist) { - return nil, &ErrMalformed{Path: chainPath, Reason: "missing commit-graph-chain"} + return nil, &MalformedError{Path: chainPath, Reason: "missing commit-graph-chain"} } return nil, err @@ -47,7 +47,7 @@ func openChain(root *os.Root, algo objectid.Algorithm) (*Reader, error) { } if len(hashes) == 0 { - return nil, &ErrMalformed{Path: chainPath, Reason: "empty chain"} + return nil, &MalformedError{Path: chainPath, Reason: "empty chain"} } layers := make([]layer, 0, len(hashes)) @@ -70,7 +70,7 @@ func openChain(root *os.Root, algo objectid.Algorithm) (*Reader, error) { if len(hashHex) != algo.HexLen() { closeLayers(layers) - return nil, &ErrMalformed{ + return nil, &MalformedError{ Path: chainPath, Reason: fmt.Sprintf("invalid graph hash length at line %d", i+1), } @@ -90,7 +90,7 @@ func openChain(root *os.Root, algo objectid.Algorithm) (*Reader, error) { closeLayers(layers) - return nil, &ErrMalformed{ + return nil, &MalformedError{ Path: relPath, Reason: fmt.Sprintf("BASE count %d does not match chain depth %d", loaded.baseCount, i), } @@ -114,7 +114,7 @@ func openChain(root *os.Root, algo objectid.Algorithm) (*Reader, error) { closeLayers(layers) - return nil, &ErrMalformed{Path: relPath, Reason: "total commit count overflow"} + return nil, &MalformedError{Path: relPath, Reason: "total commit count overflow"} } total = totalNext diff --git a/format/commitgraph/read/parents.go b/format/commitgraph/read/parents.go index 0f8024ab..fcaad8b6 100644 --- a/format/commitgraph/read/parents.go +++ b/format/commitgraph/read/parents.go @@ -35,7 +35,7 @@ func (reader *Reader) decodeParents(layer *layer, p1, p2 uint32) (ParentRef, Par } if len(parents) == 0 { - return ParentRef{}, ParentRef{}, nil, &ErrMalformed{Path: layer.path, Reason: "empty EDGE list"} + return ParentRef{}, ParentRef{}, nil, &MalformedError{Path: layer.path, Reason: "empty EDGE list"} } parent2 := ParentRef{Valid: true, Pos: parents[0]} @@ -52,7 +52,7 @@ func (reader *Reader) decodeSingleParent(raw uint32) (ParentRef, error) { } if raw&commitgraph.ParentExtraMask != 0 { - return ParentRef{}, &ErrMalformed{ + return ParentRef{}, &MalformedError{ Path: "commit-graph", Reason: "unexpected EDGE marker in single-parent slot", } diff --git a/format/commitgraph/read/position.go b/format/commitgraph/read/position.go index f92f5b3a..b2e1138b 100644 --- a/format/commitgraph/read/position.go +++ b/format/commitgraph/read/position.go @@ -31,7 +31,7 @@ func (reader *Reader) globalToPosition(global uint32) (Position, error) { } } - return Position{}, &ErrMalformed{ + return Position{}, &MalformedError{ Path: "commit-graph", Reason: fmt.Sprintf("parent global position out of range: %d", global), } diff --git a/format/commitgraph/read/read_test.go b/format/commitgraph/read/read_test.go index 80091c5b..35384930 100644 --- a/format/commitgraph/read/read_test.go +++ b/format/commitgraph/read/read_test.go @@ -157,16 +157,16 @@ func TestBloomUnavailableWithoutChangedPaths(t *testing.T) { _, err = reader.BloomFilterAt(pos) if err == nil { - t.Fatal("BloomFilterAt() error = nil, want ErrBloomUnavailable") + t.Fatal("BloomFilterAt() error = nil, want BloomUnavailableError") } - var unavailable *read.ErrBloomUnavailable + var unavailable *read.BloomUnavailableError if !errors.As(err, &unavailable) { - t.Fatalf("BloomFilterAt() error type = %T, want *ErrBloomUnavailable", err) + t.Fatalf("BloomFilterAt() error type = %T, want *BloomUnavailableError", err) } if unavailable.Pos != pos { - t.Fatalf("ErrBloomUnavailable.Pos = %+v, want %+v", unavailable.Pos, pos) + t.Fatalf("BloomUnavailableError.Pos = %+v, want %+v", unavailable.Pos, pos) } }) } diff --git a/format/pack/ingest/drain.go b/format/pack/ingest/drain.go index b92683c3..671423fb 100644 --- a/format/pack/ingest/drain.go +++ b/format/pack/ingest/drain.go @@ -18,7 +18,7 @@ func drainEntryPayload(state *ingestState, record objectRecord) (int64, uint64, reader, err := zlib.NewReader(state.stream) if err != nil { - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("open zlib stream: %v", err)} + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("open zlib stream: %v", err)} } defer func() { _ = reader.Close() }() @@ -28,7 +28,7 @@ func drainEntryPayload(state *ingestState, record objectRecord) (int64, uint64, if packfmt.IsBaseObjectType(record.packedType) { header, ok := objectheader.Encode(record.packedType, record.declaredSize) if !ok { - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: "encode object header"} + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: "encode object header"} } hashImpl, err := state.algo.New() @@ -40,7 +40,7 @@ func drainEntryPayload(state *ingestState, record objectRecord) (int64, uint64, n, err := io.Copy(hashImpl, reader) if err != nil { - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate base object: %v", err)} + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate base object: %v", err)} } total = n @@ -56,7 +56,7 @@ func drainEntryPayload(state *ingestState, record objectRecord) (int64, uint64, if record.packedType == objecttype.TypeOfsDelta || record.packedType == objecttype.TypeRefDelta { n, err := io.Copy(io.Discard, reader) if err != nil { - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate delta payload: %v", err)} + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate delta payload: %v", err)} } total = n @@ -64,5 +64,5 @@ func drainEntryPayload(state *ingestState, record objectRecord) (int64, uint64, return total, reader.InputConsumed(), zero, nil } - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: "unsupported payload type"} + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: "unsupported payload type"} } diff --git a/format/pack/ingest/entry.go b/format/pack/ingest/entry.go index f6c9074e..f89ad4c8 100644 --- a/format/pack/ingest/entry.go +++ b/format/pack/ingest/entry.go @@ -22,7 +22,7 @@ func scanOneEntry(state *ingestState, startOffset uint64) (uint64, error) { } if contentLen != record.declaredSize { - return 0, &ErrMalformedPackEntry{ + return 0, &MalformedPackEntryError{ Offset: startOffset, Reason: fmt.Sprintf("inflated size mismatch got %d want %d", contentLen, record.declaredSize), } @@ -30,7 +30,7 @@ func scanOneEntry(state *ingestState, startOffset uint64) (uint64, error) { endOffset := startOffset + uint64(record.headerLen) + consumedInput if endOffset > state.stream.consumed { - return 0, &ErrMalformedPackEntry{ + return 0, &MalformedPackEntryError{ Offset: startOffset, Reason: fmt.Sprintf("entry end offset overflow got %d > stream %d", endOffset, state.stream.consumed), } @@ -40,7 +40,7 @@ func scanOneEntry(state *ingestState, startOffset uint64) (uint64, error) { record.dataOffset = startOffset + uint64(record.headerLen) if record.packedLen < uint64(record.headerLen) { - return 0, &ErrMalformedPackEntry{Offset: startOffset, Reason: "negative payload span"} + return 0, &MalformedPackEntryError{Offset: startOffset, Reason: "negative payload span"} } crc, err := state.stream.endEntryCRC() diff --git a/format/pack/ingest/entry_prefix.go b/format/pack/ingest/entry_prefix.go index 6ffb1c56..85493798 100644 --- a/format/pack/ingest/entry_prefix.go +++ b/format/pack/ingest/entry_prefix.go @@ -16,7 +16,7 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err first, err := state.stream.ReadByte() if err != nil { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read first header byte: %v", err)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read first header byte: %v", err)} } record.packedType = objecttype.Type((first >> 4) & 0x07) @@ -28,7 +28,7 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err for b&0x80 != 0 { b, err = state.stream.ReadByte() if err != nil { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read size continuation: %v", err)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read size continuation: %v", err)} } headerLen++ @@ -37,7 +37,7 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err } if size < 0 { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: "negative declared size"} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: "negative declared size"} } record.declaredSize = size @@ -49,12 +49,12 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err err := state.stream.readFull(baseRaw) if err != nil { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read ref base: %v", err)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read ref base: %v", err)} } baseID, err := objectid.FromBytes(state.algo, baseRaw) if err != nil { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("parse ref base: %v", err)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("parse ref base: %v", err)} } record.baseObject = baseID @@ -68,11 +68,11 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err case objecttype.TypeOfsDelta: dist, consumed, err := readOfsDistanceFromStream(state.stream) if err != nil { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: err.Error()} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: err.Error()} } if startOffset <= dist { - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: "ofs base offset out of bounds"} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: "ofs base offset out of bounds"} } record.baseOffset = startOffset - dist @@ -84,9 +84,9 @@ func parseEntryPrefix(state *ingestState, startOffset uint64) (objectRecord, err headerLen += consumedUint32 case objecttype.TypeInvalid, objecttype.TypeFuture: - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} default: - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} } record.headerLen = headerLen diff --git a/format/pack/ingest/errors.go b/format/pack/ingest/errors.go index cd65d3cf..82b662b5 100644 --- a/format/pack/ingest/errors.go +++ b/format/pack/ingest/errors.go @@ -5,64 +5,64 @@ import ( "fmt" ) -// ErrInvalidPackHeader reports an invalid or unsupported pack header. -type ErrInvalidPackHeader struct { +// InvalidPackHeaderError reports an invalid or unsupported pack header. +type InvalidPackHeaderError struct { Reason string } // Error implements error. -func (err *ErrInvalidPackHeader) Error() string { - return fmt.Sprintf("format/pack/ingest: invalid pack header: %s", err.Reason) +func (err *InvalidPackHeaderError) Error() string { + return "format/pack/ingest: invalid pack header: " + err.Reason } -// ErrPackTrailerMismatch reports a mismatch between computed and trailer pack hash. -type ErrPackTrailerMismatch struct{} +// PackTrailerMismatchError reports a mismatch between computed and trailer pack hash. +type PackTrailerMismatchError struct{} // Error implements error. -func (err *ErrPackTrailerMismatch) Error() string { +func (err *PackTrailerMismatchError) Error() string { return "format/pack/ingest: pack trailer hash mismatch" } -// ErrThinPackUnresolved reports unresolved REF deltas when fixThin is disabled +// ThinPackUnresolvedError reports unresolved REF deltas when fixThin is disabled // or when required bases cannot be found in base. -type ErrThinPackUnresolved struct { +type ThinPackUnresolvedError struct { Count int } // Error implements error. -func (err *ErrThinPackUnresolved) Error() string { +func (err *ThinPackUnresolvedError) Error() string { return fmt.Sprintf("format/pack/ingest: unresolved thin deltas: %d", err.Count) } -// ErrMalformedPackEntry reports malformed entry encoding at one pack offset. -type ErrMalformedPackEntry struct { +// MalformedPackEntryError reports malformed entry encoding at one pack offset. +type MalformedPackEntryError struct { Offset uint64 Reason string } // Error implements error. -func (err *ErrMalformedPackEntry) Error() string { +func (err *MalformedPackEntryError) Error() string { return fmt.Sprintf("format/pack/ingest: malformed pack entry at offset %d: %s", err.Offset, err.Reason) } -// ErrDeltaCycle reports a detected cycle in delta dependency resolution. -type ErrDeltaCycle struct { +// DeltaCycleError reports a detected cycle in delta dependency resolution. +type DeltaCycleError struct { Offset uint64 } // Error implements error. -func (err *ErrDeltaCycle) Error() string { +func (err *DeltaCycleError) Error() string { return fmt.Sprintf("format/pack/ingest: delta cycle detected at offset %d", err.Offset) } -// ErrDestinationWrite reports destination I/O failures. -type ErrDestinationWrite struct { +// DestinationWriteError reports destination I/O failures. +type DestinationWriteError struct { Op string } // Error implements error. -func (err *ErrDestinationWrite) Error() string { - return fmt.Sprintf("format/pack/ingest: destination write failure: %s", err.Op) +func (err *DestinationWriteError) Error() string { + return "format/pack/ingest: destination write failure: " + err.Op } var errExternalThinBase = errors.New("format/pack/ingest: external thin base required") diff --git a/format/pack/ingest/flush.go b/format/pack/ingest/flush.go index 4742ead1..96753170 100644 --- a/format/pack/ingest/flush.go +++ b/format/pack/ingest/flush.go @@ -18,11 +18,11 @@ func (scanner *streamScanner) flushConsumedPrefix() error { for written < scanner.off { n, err := scanner.dstFile.Write(scanner.buf[written:scanner.off]) if err != nil { - return &ErrDestinationWrite{Op: fmt.Sprintf("write pack: %v", err)} + return &DestinationWriteError{Op: fmt.Sprintf("write pack: %v", err)} } if n == 0 { - return &ErrDestinationWrite{Op: "write pack: short write"} + return &DestinationWriteError{Op: "write pack: short write"} } written += n diff --git a/format/pack/ingest/header.go b/format/pack/ingest/header.go index 88663760..fba2b175 100644 --- a/format/pack/ingest/header.go +++ b/format/pack/ingest/header.go @@ -13,21 +13,21 @@ func readAndValidatePackHeader(state *ingestState) error { err := state.stream.readFull(hdr[:]) if err != nil { - return &ErrInvalidPackHeader{Reason: fmt.Sprintf("read header: %v", err)} + return &InvalidPackHeaderError{Reason: fmt.Sprintf("read header: %v", err)} } if binary.BigEndian.Uint32(hdr[:4]) != pack.Signature { - return &ErrInvalidPackHeader{Reason: "signature mismatch"} + return &InvalidPackHeaderError{Reason: "signature mismatch"} } version := binary.BigEndian.Uint32(hdr[4:8]) if !pack.VersionSupported(version) { - return &ErrInvalidPackHeader{Reason: fmt.Sprintf("unsupported version %d", version)} + return &InvalidPackHeaderError{Reason: fmt.Sprintf("unsupported version %d", version)} } state.objectCountHeader = binary.BigEndian.Uint32(hdr[8:12]) if state.objectCountHeader == 0 { - return &ErrInvalidPackHeader{Reason: "zero objects"} + return &InvalidPackHeaderError{Reason: "zero objects"} } return nil diff --git a/format/pack/ingest/ingest.go b/format/pack/ingest/ingest.go index df6c6627..22007d27 100644 --- a/format/pack/ingest/ingest.go +++ b/format/pack/ingest/ingest.go @@ -39,7 +39,7 @@ func ingest(state *ingestState) (out Result, err error) { } if len(state.unresolvedRefDeltas) > 0 { - return Result{}, &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} + return Result{}, &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} } err = verifyResolvedRecords(state) @@ -49,7 +49,7 @@ func ingest(state *ingestState) (out Result, err error) { err = state.packFile.Sync() if err != nil { - return Result{}, &ErrDestinationWrite{Op: fmt.Sprintf("sync pack: %v", err)} + return Result{}, &DestinationWriteError{Op: fmt.Sprintf("sync pack: %v", err)} } err = writeIdx(state) diff --git a/format/pack/ingest/ingest_test.go b/format/pack/ingest/ingest_test.go index 1bc2ec0f..13f7ee85 100644 --- a/format/pack/ingest/ingest_test.go +++ b/format/pack/ingest/ingest_test.go @@ -246,9 +246,9 @@ func TestIngestThinPackWithoutFixReturnsUnresolved(t *testing.T) { t.Fatal("Ingest error = nil, want error") } - var unresolved *ingest.ErrThinPackUnresolved + var unresolved *ingest.ThinPackUnresolvedError if !errors.As(err, &unresolved) { - t.Fatalf("Ingest error type = %T (%v), want *ErrThinPackUnresolved", err, err) + t.Fatalf("Ingest error type = %T (%v), want *ThinPackUnresolvedError", err, err) } matches, err := filepath.Glob(filepath.Join(packDir, "pack-*.pack")) @@ -362,9 +362,9 @@ func TestIngestPackTrailerMismatch(t *testing.T) { t.Fatal("Ingest error = nil, want error") } - var mismatch *ingest.ErrPackTrailerMismatch + var mismatch *ingest.PackTrailerMismatchError if !errors.As(err, &mismatch) { - t.Fatalf("Ingest error type = %T (%v), want *ErrPackTrailerMismatch", err, err) + t.Fatalf("Ingest error type = %T (%v), want *PackTrailerMismatchError", err, err) } matches, err := filepath.Glob(filepath.Join(packDir, "pack-*.pack")) diff --git a/format/pack/ingest/record_content.go b/format/pack/ingest/record_content.go index 1d4f27c3..8fef44b9 100644 --- a/format/pack/ingest/record_content.go +++ b/format/pack/ingest/record_content.go @@ -20,7 +20,7 @@ func readBaseRecordContent(state *ingestState, idx int) (objecttype.Type, []byte } if int64(len(content)) != record.declaredSize { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("base content size mismatch got %d want %d", len(content), record.declaredSize), } diff --git a/format/pack/ingest/record_delta.go b/format/pack/ingest/record_delta.go index 67db608e..4a3d5810 100644 --- a/format/pack/ingest/record_delta.go +++ b/format/pack/ingest/record_delta.go @@ -20,7 +20,7 @@ func applyDeltaRecord(state *ingestState, idx int, baseType objecttype.Type, bas } if int64(len(deltaPayload)) != record.declaredSize { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("delta payload size mismatch got %d want %d", len(deltaPayload), record.declaredSize), } @@ -28,14 +28,14 @@ func applyDeltaRecord(state *ingestState, idx int, baseType objecttype.Type, bas srcSize, dstSize, err := readDeltaHeaderSizes(deltaPayload) if err != nil { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("read delta header: %v", err), } } if srcSize != len(baseContent) { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("delta source size mismatch got %d want %d", srcSize, len(baseContent)), } @@ -43,14 +43,14 @@ func applyDeltaRecord(state *ingestState, idx int, baseType objecttype.Type, bas content, err := deltaapply.Apply(baseContent, deltaPayload) if err != nil { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("apply delta: %v", err), } } if len(content) != dstSize { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: fmt.Sprintf("delta result size mismatch got %d want %d", len(content), dstSize), } diff --git a/format/pack/ingest/record_inflate.go b/format/pack/ingest/record_inflate.go index a8d68c07..b8eca25b 100644 --- a/format/pack/ingest/record_inflate.go +++ b/format/pack/ingest/record_inflate.go @@ -12,7 +12,7 @@ import ( func inflateRecordPayload(state *ingestState, idx int) ([]byte, error) { record := state.records[idx] if record.packedLen < uint64(record.headerLen) { - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: "entry packed span underflow"} + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: "entry packed span underflow"} } compressedOffset := record.offset + uint64(record.headerLen) @@ -32,14 +32,14 @@ func inflateRecordPayload(state *ingestState, idx int) ([]byte, error) { reader, err := zlib.NewReader(section) if err != nil { - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("open payload zlib: %v", err)} + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("open payload zlib: %v", err)} } defer func() { _ = reader.Close() }() out, err := io.ReadAll(reader) if err != nil { - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate payload: %v", err)} + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate payload: %v", err)} } return out, nil diff --git a/format/pack/ingest/record_resolve.go b/format/pack/ingest/record_resolve.go index 6ef5e857..fad8ee7f 100644 --- a/format/pack/ingest/record_resolve.go +++ b/format/pack/ingest/record_resolve.go @@ -14,7 +14,7 @@ func resolveRecord(state *ingestState, idx int, visiting map[int]struct{}) (obje } if _, ok := visiting[idx]; ok { - return objecttype.TypeInvalid, nil, &ErrDeltaCycle{Offset: state.records[idx].offset} + return objecttype.TypeInvalid, nil, &DeltaCycleError{Offset: state.records[idx].offset} } visiting[idx] = struct{}{} @@ -60,7 +60,7 @@ func resolveRecord(state *ingestState, idx int, visiting map[int]struct{}) (obje case objecttype.TypeOfsDelta: baseIdx, ok := state.offsetToRecord[record.baseOffset] if !ok { - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: "missing ofs-delta base entry", } @@ -86,12 +86,12 @@ func resolveRecord(state *ingestState, idx int, visiting map[int]struct{}) (obje objecttype.TypeBlob, objecttype.TypeTag, objecttype.TypeFuture: - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: "unsupported delta type", } default: - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ Offset: record.offset, Reason: "unsupported delta type", } diff --git a/format/pack/ingest/thin_fix.go b/format/pack/ingest/thin_fix.go index 65ce131c..f21ef98a 100644 --- a/format/pack/ingest/thin_fix.go +++ b/format/pack/ingest/thin_fix.go @@ -13,11 +13,11 @@ func maybeFixThin(state *ingestState) error { } if !state.fixThin { - return &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} + return &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} } if state.base == nil { - return &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} + return &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} } hashSize := int64(state.algo.Size()) diff --git a/format/pack/ingest/trailer.go b/format/pack/ingest/trailer.go index 4dba3884..ea945b10 100644 --- a/format/pack/ingest/trailer.go +++ b/format/pack/ingest/trailer.go @@ -20,7 +20,7 @@ func (scanner *streamScanner) finishAndFlushTrailer() error { err := scanner.readFull(trailer) if err != nil { - return &ErrPackTrailerMismatch{} + return &PackTrailerMismatchError{} } scanner.packTrailer = append(scanner.packTrailer[:0], trailer...) @@ -38,7 +38,7 @@ func (scanner *streamScanner) finishAndFlushTrailer() error { computed := scanner.hash.Sum(nil) if !bytes.Equal(computed, trailer) { - return &ErrPackTrailerMismatch{} + return &PackTrailerMismatchError{} } return nil diff --git a/format/pktline/errors.go b/format/pktline/errors.go index d07227e6..866ff467 100644 --- a/format/pktline/errors.go +++ b/format/pktline/errors.go @@ -1,9 +1,6 @@ package pktline -import ( - "errors" - "fmt" -) +import "errors" var ( // ErrInvalidLength indicates a malformed 4-byte hexadecimal length header. @@ -30,5 +27,5 @@ func (e *ProtocolError) Error() string { return "pktline: protocol error" } - return fmt.Sprintf("pktline: protocol error: %s", e.Reason) + return "pktline: protocol error: " + e.Reason } diff --git a/format/sideband64k/errors.go b/format/sideband64k/errors.go index c04d7caa..44e7c165 100644 --- a/format/sideband64k/errors.go +++ b/format/sideband64k/errors.go @@ -1,9 +1,6 @@ package sideband64k -import ( - "errors" - "fmt" -) +import "errors" var ( // ErrTooLarge indicates a payload exceeds configured sideband data limits. @@ -26,5 +23,5 @@ func (e *ProtocolError) Error() string { return "sideband64k: protocol error" } - return fmt.Sprintf("sideband64k: protocol error: %s", e.Reason) + return "sideband64k: protocol error: " + e.Reason } |
