Commit 74d4fd3c authored by Arthur Silva's avatar Arthur Silva Committed by Matt Holt

improve error checking (#1938)

parent ac1f3bfa
......@@ -25,9 +25,15 @@ func TestAssetsPath(t *testing.T) {
t.Errorf("Expected path to be a .caddy folder, got: %v", actual)
}
os.Setenv("CADDYPATH", "testpath")
err := os.Setenv("CADDYPATH", "testpath")
if err != nil {
t.Error("Could not set CADDYPATH")
}
if actual, expected := AssetsPath(), "testpath"; actual != expected {
t.Errorf("Expected path to be %v, got: %v", expected, actual)
}
os.Setenv("CADDYPATH", "")
err = os.Setenv("CADDYPATH", "")
if err != nil {
t.Error("Could not set CADDYPATH")
}
}
......@@ -206,12 +206,15 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) {
// success! stop the old instance
for _, shutdownFunc := range i.onShutdown {
err := shutdownFunc()
err = shutdownFunc()
if err != nil {
return i, err
}
}
i.Stop()
err = i.Stop()
if err != nil {
return i, err
}
// Execute instantiation events
EmitEvent(InstanceStartupEvent, newInst)
......@@ -483,14 +486,14 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
if !IsUpgrade() && restartFds == nil {
// first startup means not a restart or upgrade
for _, firstStartupFunc := range inst.onFirstStartup {
err := firstStartupFunc()
err = firstStartupFunc()
if err != nil {
return err
}
}
}
for _, startupFunc := range inst.onStartup {
err := startupFunc()
err = startupFunc()
if err != nil {
return err
}
......@@ -653,7 +656,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
if fdIndex, ok := loadedGob.ListenerFds["tcp"+addr]; ok {
file := os.NewFile(fdIndex, "")
ln, err = net.FileListener(file)
file.Close()
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
......@@ -661,7 +667,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
if fdIndex, ok := loadedGob.ListenerFds["udp"+addr]; ok {
file := os.NewFile(fdIndex, "")
pc, err = net.FilePacketConn(file)
file.Close()
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
......@@ -684,7 +693,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
if err != nil {
return err
}
file.Close()
err = file.Close()
if err != nil {
return err
}
}
// packetconn
if old.packet != nil {
......@@ -696,7 +708,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
if err != nil {
return err
}
file.Close()
err = file.Close()
if err != nil {
return err
}
}
}
}
......
......@@ -136,7 +136,10 @@ func Upgrade() error {
// immediately close our dup'ed fds and the write end of our signal pipe
for _, f := range extraFiles {
f.Close()
err = f.Close()
if err != nil {
return err
}
}
// feed Caddyfile to the child
......@@ -144,7 +147,10 @@ func Upgrade() error {
if err != nil {
return err
}
wpipe.Close()
err = wpipe.Close()
if err != nil {
return err
}
// determine whether child startup succeeded
answer, readErr := ioutil.ReadAll(sigrpipe)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment