From ee7dac9e2830ea83f7638d59f237356e11179704 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 19 May 2015 12:37:57 +0100 Subject: [PATCH] Improve error messages Make clear that they come from the IP allocator, and reduce repetition in the text. Also include the nickname for other peer, if known. --- ipam/allocate.go | 2 +- ipam/allocator.go | 2 +- ipam/claim.go | 8 ++++++-- ipam/http.go | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ipam/allocate.go b/ipam/allocate.go index 320e8e02..60e564a6 100644 --- a/ipam/allocate.go +++ b/ipam/allocate.go @@ -46,7 +46,7 @@ func (g *allocate) Try(alloc *Allocator) bool { } func (g *allocate) Cancel() { - g.resultChan <- allocateResult{0, fmt.Errorf("Request Cancelled")} + g.resultChan <- allocateResult{0, fmt.Errorf("Allocate request for %s cancelled, g.ident")} } func (g *allocate) String() string { diff --git a/ipam/allocator.go b/ipam/allocator.go index 28f7f6c7..6975d5fa 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -242,7 +242,7 @@ func (alloc *Allocator) free(ident string) error { found = alloc.cancelOpsFor(&alloc.pendingClaims, ident) || found if !found { - errChan <- fmt.Errorf("No addresses for %s", ident) + errChan <- fmt.Errorf("Free: no addresses for %s", ident) return } errChan <- nil diff --git a/ipam/claim.go b/ipam/claim.go index ec7bc2bf..18e84016 100644 --- a/ipam/claim.go +++ b/ipam/claim.go @@ -37,7 +37,11 @@ func (c *claim) Try(alloc *Allocator) bool { return false } if owner != alloc.ourName { - c.resultChan <- fmt.Errorf("Address %s is owned by other peer %s", c.addr.String(), owner) + name, found := alloc.nicknames[owner] + if found { + name = " (" + name + ")" + } + c.resultChan <- fmt.Errorf("address %s is owned by other peer %s%s", c.addr.String(), owner, name) return true } // We are the owner, check we haven't given it to another container @@ -58,7 +62,7 @@ func (c *claim) Try(alloc *Allocator) bool { return true } // Addr already owned by container on this machine - c.resultChan <- fmt.Errorf("Claimed address %s is already owned by %s", c.addr.String(), existingIdent) + c.resultChan <- fmt.Errorf("address %s is already owned by %s", c.addr.String(), existingIdent) return true } diff --git a/ipam/http.go b/ipam/http.go index 39efa892..c7778996 100644 --- a/ipam/http.go +++ b/ipam/http.go @@ -12,7 +12,7 @@ import ( func badRequest(w http.ResponseWriter, err error) { http.Error(w, err.Error(), http.StatusBadRequest) - common.Warning.Println(err.Error()) + common.Warning.Println("[allocator]:", err.Error()) } // HandleHTTP wires up ipams HTTP endpoints to the provided mux. @@ -26,7 +26,7 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router) { badRequest(w, err) return } else if err := alloc.Claim(ident, ip, closedChan); err != nil { - badRequest(w, fmt.Errorf("Unable to claim IP address %s: %s", ip, err)) + badRequest(w, fmt.Errorf("Unable to claim: %s", err)) return }