Browse Source

Merge pull request #1466 from jonboulle/errors

main: catch a few unhandled errors
Jonathan Boulle 11 years ago
parent
commit
ae7280dcf3
3 changed files with 16 additions and 4 deletions
  1. 8 2
      main.go
  2. 4 1
      pkg/flags/flag.go
  3. 4 1
      pkg/flags/urls.go

+ 8 - 2
main.go

@@ -77,7 +77,10 @@ var (
 
 func init() {
 	fs.Var(clusterState, "initial-cluster-state", "Initial cluster configuration for bootstrapping")
-	clusterState.Set(etcdserver.ClusterStateValueNew)
+	if err := clusterState.Set(etcdserver.ClusterStateValueNew); err != nil {
+		// Should never happen.
+		log.Panicf("unexpected error setting up clusterState: %v", err)
+	}
 
 	fs.Var(flags.NewURLsValue("http://localhost:2380,http://localhost:7001"), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster")
 	fs.Var(flags.NewURLsValue("http://localhost:2379,http://localhost:4001"), "advertise-client-urls", "List of this member's client URLs to advertise to the rest of the cluster")
@@ -87,7 +90,10 @@ func init() {
 	fs.Var(corsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
 
 	fs.Var(proxyFlag, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(flags.ProxyValues, ", ")))
-	proxyFlag.Set(flags.ProxyValueOff)
+	if err := proxyFlag.Set(flags.ProxyValueOff); err != nil {
+		// Should never happen.
+		log.Panicf("unexpected error setting up proxyFlag: %v", err)
+	}
 
 	fs.StringVar(&clientTLSInfo.CAFile, "ca-file", "", "Path to the client server TLS CA file.")
 	fs.StringVar(&clientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")

+ 4 - 1
pkg/flags/flag.go

@@ -95,7 +95,10 @@ func SetFlagsFromEnv(fs *flag.FlagSet) {
 			key := "ETCD_" + strings.ToUpper(strings.Replace(f.Name, "-", "_", -1))
 			val := os.Getenv(key)
 			if val != "" {
-				fs.Set(f.Name, val)
+				if err := fs.Set(f.Name, val); err != nil {
+					// Should never happen
+					log.Panicf("error setting flag from env: %v", err)
+				}
 			}
 		}
 	})

+ 4 - 1
pkg/flags/urls.go

@@ -17,6 +17,7 @@
 package flags
 
 import (
+	"log"
 	"strings"
 
 	"github.com/coreos/etcd/pkg/types"
@@ -47,6 +48,8 @@ func (us *URLsValue) String() string {
 
 func NewURLsValue(init string) *URLsValue {
 	v := &URLsValue{}
-	v.Set(init)
+	if err := v.Set(init); err != nil {
+		log.Panicf("error setting URLsValue: %v", err)
+	}
 	return v
 }