Commit b1f77e9e authored by Mildred Ki'Lya's avatar Mildred Ki'Lya Committed by Shanti Bouchez-Mongardé

Improve error reporting and fix pin/set_test.go

License: MIT
Signed-off-by: default avatarMildred Ki'Lya <mildred-pub.git@mildred.fr>
parent 8f8020e8
......@@ -27,7 +27,7 @@ func (n *Node) unmarshal(encoded []byte) error {
n.Links[i] = &Link{Name: l.GetName(), Size: l.GetTsize()}
h, err := mh.Cast(l.GetHash())
if err != nil {
return fmt.Errorf("Link hash is not valid multihash. %v", err)
return fmt.Errorf("Link hash #%d is not valid multihash. %v", i, err)
}
n.Links[i].Hash = h
}
......
......@@ -79,10 +79,14 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
if err == bserv.ErrNotFound {
return nil, ErrNotFound
}
return nil, err
return nil, fmt.Errorf("Failed to get block for %s: %v", k.B58String(), err)
}
return DecodeProtobuf(b.Data)
res, err := DecodeProtobuf(b.Data)
if err != nil {
return nil, fmt.Errorf("Failed to decode Protocol Buffers: %v", err)
}
return res, nil
}
func (n *dagService) Remove(nd *Node) error {
......
......@@ -271,12 +271,12 @@ func loadSet(ctx context.Context, dag merkledag.DAGService, root *merkledag.Node
func loadMultiset(ctx context.Context, dag merkledag.DAGService, root *merkledag.Node, name string, internalKeys keyObserver) (map[key.Key]uint64, error) {
l, err := root.GetNodeLink(name)
if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to get link %s: %v", name, err)
}
internalKeys(key.Key(l.Hash))
n, err := l.GetNode(ctx, dag)
if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to get node from link %s: %v", name, err)
}
refcounts := make(map[key.Key]uint64)
......
......@@ -11,6 +11,8 @@ import (
"github.com/ipfs/go-ipfs/blockservice"
"github.com/ipfs/go-ipfs/exchange/offline"
"github.com/ipfs/go-ipfs/merkledag"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
......@@ -31,6 +33,14 @@ func TestMultisetRoundtrip(t *testing.T) {
dag := merkledag.NewDAGService(bserv)
fn := func(m map[key.Key]uint16) bool {
// Convert invalid multihash from input to valid ones
for k, v := range m {
if _, err := mh.Cast([]byte(k)); err != nil {
delete(m, k)
m[key.Key(u.Hash([]byte(k)))] = v
}
}
// Generate a smaller range for refcounts than full uint64, as
// otherwise this just becomes overly cpu heavy, splitting it
// out into too many items. That means we need to convert to
......@@ -43,6 +53,17 @@ func TestMultisetRoundtrip(t *testing.T) {
if err != nil {
t.Fatalf("storing multiset: %v", err)
}
// Check that the node n is in the DAG
k, err := n.Key()
if err != nil {
t.Fatalf("Could not get key: %v", err)
}
_, err = dag.Get(ctx, k)
if err != nil {
t.Fatalf("Could not get node: %v", err)
}
root := &merkledag.Node{}
const linkName = "dummylink"
if err := root.AddNodeLink(linkName, n); err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment