veyron2/model: profile.Init now returns an error.
Change-Id: I8bc0ec853989db4e6c57cd75f181082d776c969d
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
index 72b2774..f908d48 100644
--- a/profiles/gce/init.go
+++ b/profiles/gce/init.go
@@ -5,7 +5,9 @@
package gce
import (
+ "fmt"
"net"
+
"veyron.io/veyron/veyron/profiles"
"veyron.io/veyron/veyron2"
@@ -44,19 +46,16 @@
return "net " + p.Platform().String()
}
-func (p *profile) Init(rt veyron2.Runtime, publisher *config.Publisher) {
+func (p *profile) Init(rt veyron2.Runtime, publisher *config.Publisher) error {
if !gce.RunningOnGCE() {
- return
- // TODO(cnicolaou): add error return to init
- //return fmt.Errorf("GCE profile used on a non-GCE system")
+ return fmt.Errorf("GCE profile used on a non-GCE system")
}
if ip, err := gce.ExternalIPAddress(); err != nil {
- return
- // TODO(cnicolaou): add error return to init
- // return err
+ return err
} else {
ListenSpec.AddressChooser = func(network string, addrs []net.Addr) (net.Addr, error) {
return &net.IPAddr{IP: ip}, nil
}
}
+ return nil
}
diff --git a/profiles/generic.go b/profiles/generic.go
index 03ef607..840ff78 100644
--- a/profiles/generic.go
+++ b/profiles/generic.go
@@ -35,8 +35,9 @@
return p
}
-func (g *generic) Init(rt veyron2.Runtime, _ *config.Publisher) {
+func (g *generic) Init(rt veyron2.Runtime, _ *config.Publisher) error {
rt.Logger().VI(1).Infof("%s", g)
+ return nil
}
func (g *generic) String() string {
diff --git a/profiles/roaming/init.go b/profiles/roaming/init.go
index ce5862a..feffb24 100644
--- a/profiles/roaming/init.go
+++ b/profiles/roaming/init.go
@@ -84,7 +84,7 @@
return p.Name() + " " + p.Platform().String()
}
-func (p *profile) Init(rt veyron2.Runtime, publisher *config.Publisher) {
+func (p *profile) Init(rt veyron2.Runtime, publisher *config.Publisher) error {
log := rt.Logger()
ListenSpec = &ipc.ListenSpec{
@@ -96,9 +96,7 @@
state, err := netstate.GetAccessibleIPs()
if err != nil {
log.Infof("failed to determine network state")
- // TODO(cnicolaou): in a subsequent CL, change Init to return an error.
- return
- //return err
+ return err
}
first := state.First(netstate.IsUnicastIP)
if first == nil {
@@ -118,7 +116,7 @@
return addr, nil
}
p.gce = "+gce"
- return
+ return nil
}
}
@@ -128,7 +126,7 @@
stop, err := publisher.CreateStream(SettingsStreamName, "dhcp", ch)
if err != nil {
log.Errorf("failed to create publisher: %s", err)
- return
+ return err
}
protocol := listenProtocolFlag.Protocol
@@ -137,6 +135,7 @@
ListenSpec.AddressChooser = preferredIPAddress
log.VI(2).Infof("Initial Network Settings: %s %s available: %s", protocol, listenAddressFlag, state)
go monitorNetworkSettings(rt, stop, ch, state, ListenSpec)
+ return nil
}
// monitorNetworkSettings will monitor network configuration changes and
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index e5931ae..1911cc3 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -130,7 +130,9 @@
}
rt.publisher = config.NewPublisher()
- rt.profile.Init(rt, rt.publisher)
+ if err := rt.profile.Init(rt, rt.publisher); err != nil {
+ return nil, err
+ }
vlog.VI(2).Infof("rt.Init done")
return rt, nil