Skip to content

Commit c598a1e

Browse files
committed
Fix detecting cases when cfg.Hosts() is empty
1 parent aec0f10 commit c598a1e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

pkg/cmd/auth/logout/logout.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func logoutRun(opts *LogoutOptions) error {
7474

7575
candidates, err := cfg.Hosts()
7676
if err != nil {
77+
return err
78+
}
79+
if len(candidates) == 0 {
7780
return fmt.Errorf("not logged in to any hosts")
7881
}
7982

pkg/cmd/auth/refresh/refresh.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ func refreshRun(opts *RefreshOptions) error {
8383

8484
candidates, err := cfg.Hosts()
8585
if err != nil {
86+
return err
87+
}
88+
if len(candidates) == 0 {
8689
return fmt.Errorf("not logged in to any hosts. Use 'gh auth login' to authenticate with a host")
8790
}
8891

pkg/cmd/auth/status/status.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func statusRun(opts *StatusOptions) error {
6969
statusInfo := map[string][]string{}
7070

7171
hostnames, err := cfg.Hosts()
72-
if len(hostnames) == 0 || err != nil {
72+
if err != nil {
73+
return err
74+
}
75+
if len(hostnames) == 0 {
7376
fmt.Fprintf(stderr,
7477
"You are not logged into any GitHub hosts. Run %s to authenticate.\n", cs.Bold("gh auth login"))
7578
return cmdutil.SilentError

0 commit comments

Comments
 (0)