Skip to content

Commit

Permalink
Merge pull request #39 from libp2p/feat/better-record-err
Browse files Browse the repository at this point in the history
feat: add a better record error
  • Loading branch information
Stebalien authored May 5, 2020
2 parents 73b9483 + f8bf07c commit dc33a45
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package record

import (
"errors"
"fmt"

logging "github.com/ipfs/go-log"
)
Expand All @@ -12,6 +13,20 @@ var log = logging.Logger("routing/record")
// is not found in the Validator map of the DHT.
var ErrInvalidRecordType = errors.New("invalid record keytype")

// ErrBetterRecord is returned by a subsystem when it fails because it found a
// better record.
type ErrBetterRecord struct {
// Key is the key associated with the record.
Key string
// Value is the best value that was found, according to the record's
// validator.
Value []byte
}

func (e *ErrBetterRecord) Error() string {
return fmt.Sprintf("found better value for %q", e.Key)
}

// Validator is an interface that should be implemented by record validators.
type Validator interface {
// Validate validates the given record, returning an error if it's
Expand Down

0 comments on commit dc33a45

Please sign in to comment.