Skip to content

Commit

Permalink
fluent: finish out matrix of helper methods, and fix error handling o…
Browse files Browse the repository at this point in the history
…f the non-Must methods.

(Trying to call Build on an assembler that previously errored is very
likely to panic, so the fluent.Build function should return before
trying to do that.)
  • Loading branch information
warpfork committed Dec 4, 2020
1 parent 354f194 commit 2333d16
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fluent/fluentBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ func Build(np ipld.NodePrototype, fn func(NodeAssembler)) (ipld.Node, error) {
err := Recover(func() {
fn(fna)
})
return nb.Build(), err
if err != nil {
return nil, err
}
return nb.Build(), nil
}
func BuildMap(np ipld.NodePrototype, sizeHint int, fn func(MapAssembler)) (ipld.Node, error) {
return Build(np, func(fna NodeAssembler) { fna.CreateMap(sizeHint, fn) })
}
func BuildList(np ipld.NodePrototype, sizeHint int, fn func(ListAssembler)) (ipld.Node, error) {
return Build(np, func(fna NodeAssembler) { fna.CreateList(sizeHint, fn) })
}

func MustBuild(np ipld.NodePrototype, fn func(NodeAssembler)) ipld.Node {
Expand Down

0 comments on commit 2333d16

Please sign in to comment.