Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #701 from bboreham/684-improve-errors
Browse files Browse the repository at this point in the history
Improve ipam error messages

Closes #684.
  • Loading branch information
rade committed May 19, 2015
2 parents 9f85cbc + 0e55f75 commit f59facf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ipam/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions ipam/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions ipam/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down

0 comments on commit f59facf

Please sign in to comment.