From 79a7226b897b880e7804db51f7689bd07161dcd6 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Mon, 15 Jul 2024 14:43:41 +0200 Subject: [PATCH] Better error messages for release child prefix (#156) --- prefix.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prefix.go b/prefix.go index 825ee13..f752934 100644 --- a/prefix.go +++ b/prefix.go @@ -294,10 +294,10 @@ func (i *ipamer) ReleaseChildPrefix(ctx context.Context, child *Prefix) error { func (i *ipamer) releaseChildPrefixInternal(ctx context.Context, namespace string, child *Prefix) error { parent, err := i.PrefixFrom(ctx, child.ParentCidr) if err != nil { - return fmt.Errorf("%w: unable to find prefix for cidr:%s error:%s", ErrNotFound, child.ParentCidr, err.Error()) + return fmt.Errorf("%w: unable to find prefix for cidr:%q error:%s", ErrNotFound, child.ParentCidr, err.Error()) } - if parent == nil { - return fmt.Errorf("prefix %s is no child prefix", child.Cidr) + if parent == nil || !parent.isParent { + return fmt.Errorf("prefix:%q is no child prefix", child.Cidr) } if len(child.ips) > 2 { return fmt.Errorf("prefix %s has ips, deletion not possible", child.Cidr) @@ -306,12 +306,12 @@ func (i *ipamer) releaseChildPrefixInternal(ctx context.Context, namespace strin parent.availableChildPrefixes[child.Cidr] = true _, err = i.storage.UpdatePrefix(ctx, *parent, namespace) if err != nil { - return fmt.Errorf("unable to release prefix %v:%w", child, err) + return fmt.Errorf("unable to update parent:%q to release child prefix:%q :%w", child.ParentCidr, child.Cidr, err) } _, err = i.DeletePrefix(ctx, child.Cidr) if err != nil { - return fmt.Errorf("unable to release prefix %v:%w", child, err) + return fmt.Errorf("unable to delete child prefix:%q :%w", child.Cidr, err) } return nil