daemon: improve some errors
use pkg/errors for all errors in this file, and wrap some errors to provide context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8a147a8c80
commit
986725b466
|
@ -5,7 +5,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -51,7 +50,7 @@ func setDefaultUmask() error {
|
||||||
desiredUmask := 0022
|
desiredUmask := 0022
|
||||||
unix.Umask(desiredUmask)
|
unix.Umask(desiredUmask)
|
||||||
if umask := unix.Umask(desiredUmask); umask != desiredUmask {
|
if umask := unix.Umask(desiredUmask); umask != desiredUmask {
|
||||||
return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask)
|
return errors.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -91,25 +90,25 @@ func (cli *DaemonCli) getSwarmRunRoot() string {
|
||||||
func allocateDaemonPort(addr string) error {
|
func allocateDaemonPort(addr string) error {
|
||||||
host, port, err := net.SplitHostPort(addr)
|
host, port, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "error parsing tcp address")
|
||||||
}
|
}
|
||||||
|
|
||||||
intPort, err := strconv.Atoi(port)
|
intPort, err := strconv.Atoi(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "error parsing tcp address")
|
||||||
}
|
}
|
||||||
|
|
||||||
var hostIPs []net.IP
|
var hostIPs []net.IP
|
||||||
if parsedIP := net.ParseIP(host); parsedIP != nil {
|
if parsedIP := net.ParseIP(host); parsedIP != nil {
|
||||||
hostIPs = append(hostIPs, parsedIP)
|
hostIPs = append(hostIPs, parsedIP)
|
||||||
} else if hostIPs, err = net.LookupIP(host); err != nil {
|
} else if hostIPs, err = net.LookupIP(host); err != nil {
|
||||||
return fmt.Errorf("failed to lookup %s address in host specification", host)
|
return errors.Errorf("failed to lookup %s address in host specification", host)
|
||||||
}
|
}
|
||||||
|
|
||||||
pa := portallocator.Get()
|
pa := portallocator.Get()
|
||||||
for _, hostIP := range hostIPs {
|
for _, hostIP := range hostIPs {
|
||||||
if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
||||||
return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
return errors.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue