From 2333d16d735239100f5926f3d07fd970984fbf73 Mon Sep 17 00:00:00 2001 From: Eric Myhre Date: Fri, 4 Dec 2020 14:17:18 +0100 Subject: [PATCH] fluent: finish out matrix of helper methods, and fix error handling of 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.) --- fluent/fluentBuilder.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fluent/fluentBuilder.go b/fluent/fluentBuilder.go index 6ca269c4..c0842c64 100644 --- a/fluent/fluentBuilder.go +++ b/fluent/fluentBuilder.go @@ -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 {