Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Oct 22, 2019
1 parent 02f0990 commit b9b08f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions command/assign_user_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func (c *AssignUserGroupsCommand) Run(args []string) int {
select {
case u := <-getUserCh:
if u.Err != nil {
c.Logger.Printf("Failed to resolve user ID: %v\n", err)
c.Logger.Printf("Failed to resolve user ID: %v\n", u.Err)
return 1
}
user = u.User
case g := <-listGroupsCh:
if g.Err != nil {
c.Logger.Printf("Failed to fetch list of groups: %v\n", err)
c.Logger.Printf("Failed to fetch list of groups: %v\n", g.Err)
return 1
}
if g.Resp.StatusCode != http.StatusOK {
Expand Down
2 changes: 1 addition & 1 deletion command/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Links
"Name": g.Profile.Name,
"LinkUsers": getLinkFromGroup(g, "users"),
"LinkApps": getLinkFromGroup(g, "apps"),
"Description": FirstNonEmptyStr(g.Profile.Description, "[None]"),
"Description": Coalesce(g.Profile.Description, "[None]"),
})
return res
}
Expand Down
4 changes: 2 additions & 2 deletions command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func FillTemplateMessage(msg string, filler map[string]interface{}) (string, err
return strings.TrimSpace(builder.String()), nil
}

// FirstNonEmptyString returns the first non-empty string
// Coalesce returns the first non-empty string
// it encounters amongst the arguments supplied to the function.
func FirstNonEmptyStr(args ...string) string {
func Coalesce(args ...string) string {
for _, v := range args {
if v != "" {
return v
Expand Down

0 comments on commit b9b08f2

Please sign in to comment.