From a786b12b68ac5bf01a594da0faf51e58659b22b7 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Wed, 23 Jun 2021 12:27:58 +0200 Subject: [PATCH] static ipam: decide wrong cidr error msg Signed-off-by: Miguel Duarte Barroso --- plugins/ipam/static/main.go | 5 +++-- plugins/ipam/static/static_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/ipam/static/main.go b/plugins/ipam/static/main.go index ed75d1fe..9156cad4 100644 --- a/plugins/ipam/static/main.go +++ b/plugins/ipam/static/main.go @@ -161,7 +161,7 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) { ip, subnet, err := net.ParseCIDR(ipstr) if err != nil { - return nil, "", err + return nil, "", fmt.Errorf("the 'ip' field is expected to be in CIDR notation, got: '%s'", ipstr) } addr := Address{ @@ -213,7 +213,8 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) { for i := range n.IPAM.Addresses { ip, addr, err := net.ParseCIDR(n.IPAM.Addresses[i].AddressStr) if err != nil { - return nil, "", err + return nil, "", fmt.Errorf( + "the 'address' field is expected to be in CIDR notation, got: '%s'", n.IPAM.Addresses[i].AddressStr) } n.IPAM.Addresses[i].Address = *addr n.IPAM.Addresses[i].Address.IP = ip diff --git a/plugins/ipam/static/static_test.go b/plugins/ipam/static/static_test.go index 47a0078a..5ce78096 100644 --- a/plugins/ipam/static/static_test.go +++ b/plugins/ipam/static/static_test.go @@ -575,8 +575,8 @@ var _ = Describe("static Operations", func() { _, _, err := testutils.CmdAddWithArgs(args, func() error { return cmdAdd(args) }) - Expect(err).Should( - MatchError(fmt.Sprintf("invalid CIDR address: %s", ipStr))) + Expect(err).Should(MatchError( + fmt.Sprintf("the 'address' field is expected to be in CIDR notation, got: '%s'", ipStr))) }) } })