Skip to content

Commit

Permalink
fix: handle new ProtoNode errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 4, 2022
1 parent 3e6753f commit 36ddd8d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,10 @@ func getFileHandle(r *mfs.Root, path string, create bool, builder cid.Builder) (
}

nd := dag.NodeWithData(ft.FilePBData(nil, 0))
nd.SetCidBuilder(builder)
err = nd.SetCidBuilder(builder)
if err != nil {
return nil, err
}
err = pdir.AddChild(fname, nd)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
Cid: c,
}
}
dagnode.SetLinks(links)
if err := dagnode.SetLinks(links); err != nil {
return nil, err
}

return dagnode, nil
}
Expand Down
4 changes: 3 additions & 1 deletion core/coreapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
Cid: c,
}
}
dagnode.SetLinks(links)
if err := dagnode.SetLinks(links); err != nil {
return nil, err
}

return dagnode, nil
}
5 changes: 4 additions & 1 deletion core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
md := dagtest.Mock()
emptyDirNode := ft.EmptyDirNode()
// Use the same prefix for the "empty" MFS root as for the file adder.
emptyDirNode.SetCidBuilder(fileAdder.CidBuilder)
err := emptyDirNode.SetCidBuilder(fileAdder.CidBuilder)
if err != nil {
return nil, err
}
mr, err := mfs.NewRoot(ctx, md, emptyDirNode, nil)
if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions core/coredag/dagpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
return nil, err
}

nd.SetCidBuilder(cidPrefix(mhType, mhLen))
err = nd.SetCidBuilder(cidPrefix(mhType, mhLen))
if err != nil {
return nil, err
}

return []ipld.Node{nd}, nil
}
Expand All @@ -40,7 +43,10 @@ func dagpbRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
return nil, err
}

nd.SetCidBuilder(cidPrefix(mhType, mhLen))
err = nd.SetCidBuilder(cidPrefix(mhType, mhLen))
if err != nil {
return nil, err
}

return []ipld.Node{nd}, nil
}
Expand Down
10 changes: 8 additions & 2 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func (adder *Adder) mfsRoot() (*mfs.Root, error) {
return adder.mroot, nil
}
rnode := unixfs.EmptyDirNode()
rnode.SetCidBuilder(adder.CidBuilder)
err := rnode.SetCidBuilder(adder.CidBuilder)
if err != nil {
return nil, err
}
mr, err := mfs.NewRoot(adder.ctx, adder.dagService, rnode, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -384,7 +387,10 @@ func (adder *Adder) addSymlink(path string, l *files.Symlink) error {
}

dagnode := dag.NodeWithData(sdata)
dagnode.SetCidBuilder(adder.CidBuilder)
err = dagnode.SetCidBuilder(adder.CidBuilder)
if err != nil {
return err
}
err = adder.dagService.Add(adder.ctx, dagnode)
if err != nil {
return err
Expand Down

0 comments on commit 36ddd8d

Please sign in to comment.