mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
Remove panic() and handle it appropriately (#5807)
This is an effort to remove panic from the source. Add a new call called CriticialIf, that calls LogIf and exits. Replace panics with one of CriticalIf, FatalIf and a return of error.
This commit is contained in:
@@ -19,7 +19,6 @@ package target
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -118,24 +117,28 @@ func (target *HTTPClientTarget) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func mustGetNewUUID() string {
|
||||
func getNewUUID() (string, error) {
|
||||
uuid, err := uuid.New()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("%s. Unable to generate random UUID", err))
|
||||
return "", err
|
||||
}
|
||||
|
||||
return uuid.String()
|
||||
return uuid.String(), nil
|
||||
}
|
||||
|
||||
// NewHTTPClientTarget - creates new HTTP client target.
|
||||
func NewHTTPClientTarget(host xnet.Host, w http.ResponseWriter) *HTTPClientTarget {
|
||||
func NewHTTPClientTarget(host xnet.Host, w http.ResponseWriter) (*HTTPClientTarget, error) {
|
||||
uuid, err := getNewUUID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &HTTPClientTarget{
|
||||
id: event.TargetID{"httpclient" + "+" + mustGetNewUUID() + "+" + host.Name, host.Port.String()},
|
||||
id: event.TargetID{"httpclient" + "+" + uuid + "+" + host.Name, host.Port.String()},
|
||||
w: w,
|
||||
eventCh: make(chan []byte),
|
||||
DoneCh: make(chan struct{}),
|
||||
stopCh: make(chan struct{}),
|
||||
}
|
||||
c.start()
|
||||
return c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -112,7 +112,10 @@ func NewNATSTarget(id string, args NATSArgs) (*NATSTarget, error) {
|
||||
|
||||
clientID := args.Streaming.ClientID
|
||||
if clientID == "" {
|
||||
clientID = mustGetNewUUID()
|
||||
clientID, err = getNewUUID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
connOpts := []stan.Option{stan.NatsURL(addressURL)}
|
||||
|
||||
Reference in New Issue
Block a user