Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Handle url.Error when vmpooler inaccessible
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmccabe committed Jul 25, 2018
1 parent 4bedb3a commit aadb599
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions commands/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"net/url"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -45,12 +46,12 @@ func runMenu(cmd *cobra.Command, args []string) {

templates, err := vmclient.ListTemplates()
if err != nil {
fmt.Println("error getting templates: %s", err)
errorMenu(err)
}

virtualmachines, err := vmclient.GetAll()
if err != nil {
fmt.Println("error getting virtualmachines: %s", err)
errorMenu(err)
}

plugin := bitbar.New()
Expand Down Expand Up @@ -225,3 +226,20 @@ func getTemplateOS(template string) string {
parts := strings.Split(template, "-")
return parts[0]
}

func errorMenu(err error) {
var errMsg string

switch err.(type) {
case *url.Error:
errMsg = "Unable to connect to VMPooler"
default:
errMsg = fmt.Sprintf("%s ...", err.Error()[:12])
}
plugin := bitbar.New()
plugin.StatusLine("VMs: ⛔️").Color("red")
menu := plugin.NewSubMenu()
menu.Line(errMsg).CopyToClipboard(err.Error())
fmt.Print(plugin.Render())
os.Exit(1)
}

0 comments on commit aadb599

Please sign in to comment.