Skip to content

Commit

Permalink
fix error formatting of ErrWrongSequence
Browse files Browse the repository at this point in the history
since .Seq() wasn't called on the stored field it printed the internal struct value of the message instead.

updates #40
  • Loading branch information
cryptix committed Dec 20, 2019
1 parent 0aface5 commit e1167f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 15 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
16 changes: 3 additions & 13 deletions plugins/gossip/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"golang.org/x/sync/errgroup"
"time"

"github.com/go-kit/kit/log"
Expand All @@ -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,
Expand Down Expand Up @@ -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}
}
}
}
Expand Down

0 comments on commit e1167f6

Please sign in to comment.