Merge pull request #262 from sthulb/panics

Fix for panics when no active host is set
This commit is contained in:
Evan Hazlett 2015-01-15 22:55:43 -05:00
commit 6ea17eee0d
3 changed files with 17 additions and 1 deletions

View File

@ -267,6 +267,15 @@ func cmdLs(c *cli.Context) {
for _, host := range hostList {
if !quiet {
tmpHost, err := store.GetActive()
if err != nil {
log.Errorf("There's a problem with the active host: %s", err)
}
if tmpHost == nil {
log.Errorf("There's a problem finding the active host")
}
go getHostState(host, *store, hostListItems)
} else {
fmt.Fprintf(w, "%s\n", host.Name)
@ -410,6 +419,10 @@ func getHost(c *cli.Context) *Host {
if err != nil {
log.Fatalf("unable to get active host: %v", err)
}
if host == nil {
log.Fatal("unable to get active host, active file not found")
}
return host
}
@ -437,7 +450,7 @@ func getHostState(host Host, store Store, hostListItems chan<- hostListItem) {
isActive, err := store.IsActive(&host)
if err != nil {
log.Errorf("error determining whether host %q is active: %s",
log.Debugf("error determining whether host %q is active: %s",
host.Name, err)
}

View File

@ -64,6 +64,7 @@ func (s *Store) Remove(name string, force bool) error {
if err != nil {
return err
}
if active != nil && active.Name == name {
if err := s.RemoveActive(); err != nil {
return err

View File

@ -189,6 +189,7 @@ func TestStoreGetSetActive(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if host != nil {
t.Fatalf("GetActive: Active host should not exist")
}
@ -227,6 +228,7 @@ func TestStoreGetSetActive(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if host != nil {
t.Fatalf("Active host %s is not nil", host.Name)
}