Skip to content

Commit

Permalink
[fix] do not discard errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Mar 6, 2020
1 parent 2283c05 commit 445bf1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (x *CtlCommand) status(rpcc *xmlrpcclient.XMLRPCClient, processes []string)
if reply, err := rpcc.GetAllProcessInfo(); err == nil {
x.showProcessInfo(&reply, processesMap)
} else {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
Expand Down Expand Up @@ -245,6 +246,7 @@ func (x *CtlCommand) shutdown(rpcc *xmlrpcclient.XMLRPCClient) {
fmt.Printf("Hmmm! Something gone wrong?!\n")
}
} else {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
Expand All @@ -263,6 +265,7 @@ func (x *CtlCommand) reload(rpcc *xmlrpcclient.XMLRPCClient) {
fmt.Printf("Removed Groups: %s\n", strings.Join(reply.RemovedGroup, ","))
}
} else {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
Expand Down
19 changes: 7 additions & 12 deletions xmlrpcclient/xmlrpc-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (r *XMLRPCClient) processResponse(resp *http.Response, processBody func(io.
func (r *XMLRPCClient) postInetHTTP(method string, url string, data interface{}, processBody func(io.ReadCloser, error)) {
req, err := r.createHTTPRequest(method, url, data)
if err != nil {
processBody(emptyReader, err)
return
}

Expand All @@ -122,9 +123,7 @@ func (r *XMLRPCClient) postInetHTTP(method string, url string, data interface{},

resp, err := http.DefaultClient.Do(req)
if err != nil {
if r.verbose {
fmt.Println("Fail to send request to supervisord:", err)
}
processBody(emptyReader, fmt.Errorf("Fail to send http request to supervisord: %s", err))
return
}
r.processResponse(resp, processBody)
Expand All @@ -140,35 +139,31 @@ func (r *XMLRPCClient) postUnixHTTP(method string, path string, data interface{}
conn, err = net.Dial("unix", path)
}
if err != nil {
if r.verbose {
fmt.Printf("Fail to connect unix socket path: %s\n", r.serverurl)
}
processBody(emptyReader, fmt.Errorf("Fail to connect unix socket path: %s. %s", r.serverurl, err))
return
}
defer conn.Close()

if r.timeout > 0 {
if err := conn.SetDeadline(time.Now().Add(r.timeout)); err != nil {
processBody(emptyReader, err)
return
}
}
req, err := r.createHTTPRequest(method, "/RPC2", data)

if err != nil {
processBody(emptyReader, fmt.Errorf("Fail to create http request. %s", err))
return
}
err = req.Write(conn)
if err != nil {
if r.verbose {
fmt.Printf("Fail to write to unix socket %s\n", r.serverurl)
}
processBody(emptyReader, fmt.Errorf("Fail to write to unix socket %s", r.serverurl))
return
}
resp, err := http.ReadResponse(bufio.NewReader(conn), req)
if err != nil {
if r.verbose {
fmt.Printf("Fail to read response %s\n", err)
}
processBody(emptyReader, fmt.Errorf("Fail to read response %s", err))
return
}
r.processResponse(resp, processBody)
Expand Down

0 comments on commit 445bf1f

Please sign in to comment.