~whereswaldon/forest-go

9cb49ff8b0902aa5c8ebfddc0dc83eefce38b02f — Chris Waldon 7 months ago af9b680
fix(grove): ensure write errors are caught on node create
1 files changed, 6 insertions(+), 2 deletions(-)

M grove/grove.go
M grove/grove.go => grove/grove.go +6 -2
@@ 322,7 322,7 @@ func (g *Grove) CacheChildInfo(node forest.Node) {
// Add inserts the node into the grove. If the given node is already in the
// grove, Add will do nothing. It is not an error to insert a node more than
// once.
func (g *Grove) Add(node forest.Node) error {
func (g *Grove) Add(node forest.Node) (err error) {
	g.CacheChildInfo(node)
	if _, alreadyPresent, err := g.Get(node.ID()); err != nil {
		return fmt.Errorf("failed checking whether node already in grove: %w", err)


@@ 339,7 339,11 @@ func (g *Grove) Add(node forest.Node) error {
	if err != nil {
		return fmt.Errorf("failed to create file for node %s: %w", id, err)
	}
	defer nodeFile.Close()
	defer func() {
		if e := nodeFile.Close(); err != nil {
			err = fmt.Errorf("failed closing node: %w", e)
		}
	}()

	_, err = nodeFile.Write(data)
	if err != nil {