diff --git a/errors.go b/errors.go index 0020fca5..cc71e28b 100644 --- a/errors.go +++ b/errors.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/pkg/errors" + "go.cryptoscope.co/margaret" ) var ErrShuttingDown = errors.Errorf("ssb: shutting down now") // this is fine @@ -56,3 +57,17 @@ func (ewt ErrWrongType) Error() string { } var ErrUnuspportedFormat = errors.Errorf("ssb: unsupported format") + +// ErrWrongSequence is returned if there is a glitch on the current +// sequence number of the feed between the offsetlog and the index +type ErrWrongSequence struct { + Ref *FeedRef + Indexed, Offset margaret.Seq +} + +func (e ErrWrongSequence) Error() string { + return fmt.Sprintf("consistency error: message sequence missmatch for feed %s. Offset:%d Index:%d", + e.Ref.Ref(), + e.Offset.Seq(), + e.Indexed.Seq()) +} diff --git a/plugins/gossip/fetch.go b/plugins/gossip/fetch.go index c438ff92..24993614 100644 --- a/plugins/gossip/fetch.go +++ b/plugins/gossip/fetch.go @@ -6,8 +6,6 @@ import ( "bytes" "context" "encoding/json" - "fmt" - "golang.org/x/sync/errgroup" "time" "github.com/go-kit/kit/log" @@ -19,21 +17,13 @@ import ( "go.cryptoscope.co/margaret" "go.cryptoscope.co/muxrpc" "go.cryptoscope.co/muxrpc/codec" + "golang.org/x/sync/errgroup" + "go.cryptoscope.co/ssb" "go.cryptoscope.co/ssb/graph" "go.cryptoscope.co/ssb/message" ) -type ErrWrongSequence struct { - Ref *ssb.FeedRef - Indexed, Stored margaret.Seq -} - -func (e ErrWrongSequence) Error() string { - return fmt.Sprintf("consistency error: wrong stored message sequence for feed %s. stored:%d indexed:%d", - e.Ref.Ref(), e.Stored, e.Indexed) -} - func (h *handler) fetchAll( ctx context.Context, e muxrpc.Endpoint, @@ -182,7 +172,7 @@ func (g *handler) fetchFeed( // make sure our house is in order if hasSeq := latestMsg.Seq(); hasSeq != latestSeq.Seq() { - return ErrWrongSequence{Stored: latestMsg, Indexed: latestSeq, Ref: fr} + return ssb.ErrWrongSequence{Ref: fr, Offset: latestMsg, Indexed: latestSeq} } } }