Skip to content

Commit a4d4085

Browse files
geofffranksameowlia
authored andcommitted
Catch or explicitly ignore unhandled errors
1 parent 5b920eb commit a4d4085

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+127
-18
lines changed

src/code.cloudfoundry.org/bosh-dns-adapter/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Config struct {
2727
}
2828

2929
func init() {
30+
// #nosec G104 - don't handle error here - only thing that would be returned is if we had an empty name passed in, and we're in an init block with limitid handling capability
3031
validator.SetValidationFunc("cidr", func(v interface{}, param string) error {
3132
cidr, ok := v.(string)
3233
if !ok {

src/code.cloudfoundry.org/bosh-dns-adapter/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ func main() {
9393
}
9494

9595
go func() {
96-
http.Serve(l, metricsWrap("GetIPs", http.HandlerFunc(getIPsHandler.ServeHTTP)))
96+
err = http.Serve(l, metricsWrap("GetIPs", http.HandlerFunc(getIPsHandler.ServeHTTP)))
97+
logger.Info("http-server-returned", lager.Data{"error": err})
9798
}()
9899

99100
uptimeSource := metrics.NewUptimeSource()
@@ -122,6 +123,9 @@ func main() {
122123
logger.Info("server-started")
123124
sig := <-signalChannel
124125
monitor.Signal(sig)
125-
l.Close()
126+
err = l.Close()
127+
if err != nil {
128+
logger.Error("erro-closing-server", err)
129+
}
126130
logger.Info("server-stopped")
127131
}

src/code.cloudfoundry.org/bosh-dns-adapter/sdcclient/service_discovery_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (s *ServiceDiscoveryClient) IPs(infrastructureName string) ([]string, error
8686
}
8787

8888
defer func(httpResp *http.Response) {
89+
// #nosec G104 - ignore errors in the defer block, this response was bad anyway and we just want to best-effort clean it up
8990
io.Copy(io.Discard, httpResp.Body)
91+
// #nosec G104 - ignore errors in the defer block, this response was bad anyway and we just want to best-effort clean it up
9092
httpResp.Body.Close()
9193
}(httpResp)
9294

@@ -102,6 +104,7 @@ func (s *ServiceDiscoveryClient) IPs(infrastructureName string) ([]string, error
102104
}
103105

104106
bytes, err := io.ReadAll(httpResp.Body)
107+
// #nosec G104 - ignore closing body errors. we either have all the data and can keep going
105108
httpResp.Body.Close()
106109
if err != nil {
107110
return []string{}, err

src/code.cloudfoundry.org/cf-pusher/cmd/cf-pusher/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,13 @@ func main() {
231231
if err := apiConnector.Connect(); err != nil {
232232
log.Fatalf("connecting to api: %s", err)
233233
}
234-
adapter.TargetOrg(scaleGroup.Org)
235-
adapter.TargetSpace(scaleGroup.Space)
234+
if err := adapter.TargetOrg(scaleGroup.Org); err != nil {
235+
log.Fatalf("targeting org %s: %s", scaleGroup.Org, err)
236+
}
237+
238+
if err := adapter.TargetSpace(scaleGroup.Space); err != nil {
239+
log.Fatalf("targeting space %s: %s", scaleGroup.Space, err)
240+
}
236241

237242
// declare what apps we expect
238243
expectedApps := map[string]int{

src/code.cloudfoundry.org/policy-server/cmd/policy-server-asg-syncer/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ func main() {
158158

159159
err = <-monitor.Wait()
160160
if connectionPool != nil {
161-
connectionPool.Close()
161+
closeErr := connectionPool.Close()
162+
if closeErr != nil {
163+
logger.Error("error-closing-connection-pool", err)
164+
}
162165
}
163166
if err != nil {
164167
logger.Error("exited-with-failure", err)

src/code.cloudfoundry.org/policy-server/cmd/policy-server-internal/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ func main() {
202202

203203
err = <-monitor.Wait()
204204
if connectionPool != nil {
205-
connectionPool.Close()
205+
closeErr := connectionPool.Close()
206+
if closeErr != nil {
207+
logger.Error("error-closing-connection-pool", err)
208+
}
206209
}
207210
if err != nil {
208211
logger.Error("exited-with-failure", err)

src/code.cloudfoundry.org/policy-server/cmd/policy-server/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ func main() {
324324

325325
err = <-monitor.Wait()
326326
if connectionPool != nil {
327-
connectionPool.Close()
327+
closeErr := connectionPool.Close()
328+
if closeErr != nil {
329+
logger.Error("error-closing-connection-pool", err)
330+
}
328331
}
329332
if err != nil {
330333
logger.Error("exited-with-failure", err)

src/code.cloudfoundry.org/policy-server/handlers/asgs_index.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (h *AsgsIndex) ServeHTTP(w http.ResponseWriter, req *http.Request) {
5252
}
5353

5454
w.WriteHeader(http.StatusOK)
55+
// #nosec G104 - ignore errors writing http responses to avoid spamming logs during a DoS
5556
w.Write(bytes)
5657
}
5758

src/code.cloudfoundry.org/policy-server/handlers/policies_cleanup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ func (h *PoliciesCleanup) ServeHTTP(w http.ResponseWriter, req *http.Request) {
5959
}
6060

6161
w.WriteHeader(http.StatusOK)
62+
// #nosec G104 - ignore errors writing http responses to avoid spamming logs during a DoS
6263
w.Write(bytes)
6364
}

src/code.cloudfoundry.org/policy-server/handlers/policies_create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ func (h *PoliciesCreate) ServeHTTP(w http.ResponseWriter, req *http.Request) {
9696

9797
logger.Info("created-policies", lager.Data{"policies": policies, "userName": tokenData.UserName})
9898
w.WriteHeader(http.StatusOK)
99+
// #nosec G104 - ignore error writing http response to avoid spamming logs on a DoS
99100
w.Write([]byte("{}"))
100101
}

0 commit comments

Comments
 (0)