Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes for better error handling following review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
obourdon committed May 13, 2016
1 parent 71f9521 commit 40e39c8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
8 changes: 0 additions & 8 deletions core/serror/serror.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ limitations under the License.

package serror

import (
"errors"
)

var (
ErrBadAddress = errors.New("Address for binding can not contain comma")
)

type SnapError interface {
error
Fields() map[string]interface{}
Expand Down
5 changes: 2 additions & 3 deletions mgmt/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ func (s *Server) Name() string {
return "REST"
}

func (s *Server) SetAddress(addrString string, dfltPort int) error {
func (s *Server) SetAddress(addrString string, dfltPort int) {
restLogger.Info(fmt.Sprintf("Setting address to: [%v] Default port: %v", addrString, dfltPort))
// In the future, we could extend this to support multiple comma separated IP[:port] values
if strings.Index(addrString, ",") != -1 {
return serror.ErrBadAddress
restLogger.Fatal("Invalid address")
}
// If no port is specified, use default port
if strings.Index(addrString, ":") != -1 {
Expand All @@ -322,7 +322,6 @@ func (s *Server) SetAddress(addrString string, dfltPort int) error {
s.addrString = fmt.Sprintf("%s:%d", addrString, dfltPort)
}
restLogger.Info(fmt.Sprintf("Address used for binding: [%v]", s.addrString))
return nil
}

func (s *Server) Start() error {
Expand Down
6 changes: 3 additions & 3 deletions snapd.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func checkCmdLineFlags(ctx *cli.Context) error {
addr := ctx.String("api-addr")
// Contains a comma
if strings.Index(addr, ",") != -1 {
return serror.ErrBadAddress
return errors.New("Invalid address")
}
idx := strings.Index(addr, ":")
// Port is specified in address string
Expand All @@ -682,7 +682,7 @@ func checkCmdLineFlags(ctx *cli.Context) error {
func applyCmdLineFlags(cfg *Config, ctx *cli.Context) {
err := checkCmdLineFlags(ctx)
if err != nil {
panic(err)
log.Fatal(err)
}
invertBoolean := true
// apply any command line flags that might have been set, first for the
Expand All @@ -699,7 +699,7 @@ func applyCmdLineFlags(cfg *Config, ctx *cli.Context) {
// next for the RESTful server related flags
cfg.RestAPI.Enable = setBoolVal(cfg.RestAPI.Enable, ctx, "disable-api", invertBoolean)
cfg.RestAPI.Port = setIntVal(cfg.RestAPI.Port, ctx, "api-port")
cfg.RestAPI.Address = setStringVal(cfg.RestAPI.Address, ctx, "ip-addr")
cfg.RestAPI.Address = setStringVal(cfg.RestAPI.Address, ctx, "api-addr")
cfg.RestAPI.HTTPS = setBoolVal(cfg.RestAPI.HTTPS, ctx, "rest-https")
cfg.RestAPI.RestCertificate = setStringVal(cfg.RestAPI.RestCertificate, ctx, "rest-cert")
cfg.RestAPI.RestKey = setStringVal(cfg.RestAPI.RestKey, ctx, "rest-key")
Expand Down

0 comments on commit 40e39c8

Please sign in to comment.