Skip to content

Commit 815f461

Browse files
committed
more strict erroring around missing user/token
1 parent b1d5264 commit 815f461

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

command/root.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ func BasicClient() (*api.Client, error) {
109109
opts = append(opts, apiVerboseLog())
110110
}
111111
opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", Version)))
112-
if c, err := context.ParseDefaultConfig(); err == nil {
113-
if token, err := c.Get(defaultHostname, "oauth_token"); err == nil {
114-
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
115-
}
112+
113+
c, err := context.ParseDefaultConfig()
114+
if err != nil {
115+
return nil, err
116116
}
117+
118+
token, err := c.Get(defaultHostname, "oauth_token")
119+
if token == "" || err != nil {
120+
return nil, err
121+
}
122+
123+
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
117124
return api.NewClient(opts...), nil
118125
}
119126

context/context.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ func (c *fsContext) AuthToken() (string, error) {
190190
return "", err
191191
}
192192

193-
return config.Get(defaultHostname, "oauth_token")
193+
token, err := config.Get(defaultHostname, "token")
194+
if token == "" || err != nil {
195+
return "", err
196+
}
197+
198+
return token, nil
194199
}
195200

196201
func (c *fsContext) SetAuthToken(t string) {
@@ -203,7 +208,12 @@ func (c *fsContext) AuthLogin() (string, error) {
203208
return "", err
204209
}
205210

206-
return config.Get(defaultHostname, "user")
211+
login, err := config.Get(defaultHostname, "user")
212+
if login == "" || err != nil {
213+
return "", err
214+
}
215+
216+
return login, nil
207217
}
208218

209219
func (c *fsContext) Branch() (string, error) {

0 commit comments

Comments
 (0)