Skip to content

Commit 67f8c36

Browse files
authored
Merge pull request #22 from gomicro/empty-token
that way wasn't working, actually show an error if the token is empty
2 parents f45e0d0 + b469189 commit 67f8c36

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

client/context.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ const (
88
clientConextKey ctxKey = "client"
99
)
1010

11-
func WithClient(ctx context.Context, tkn string) context.Context {
12-
ctx, cancel := context.WithCancelCause(ctx)
13-
11+
func WithClient(ctx context.Context, tkn string) (context.Context, error) {
1412
c, err := New(ctx, tkn)
1513
if err != nil {
16-
cancel(err)
14+
return nil, err
1715
}
1816

19-
return context.WithValue(ctx, clientConextKey, c)
17+
return context.WithValue(ctx, clientConextKey, c), nil
2018
}
2119

2220
func ClientFromContext(ctx context.Context) (*Client, error) {

cmd/root.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ func Execute() {
4242
c.Github.Token = tkn
4343
}
4444

45-
ctx := client.WithClient(context.Background(), c.Github.Token)
45+
ctx, err := client.WithClient(context.Background(), c.Github.Token)
46+
if err != nil {
47+
fmt.Printf("Error: %s\n", err.Error())
48+
os.Exit(1)
49+
}
4650

47-
if err := rootCmd.ExecuteContext(ctx); err != nil {
51+
err = rootCmd.ExecuteContext(ctx)
52+
if err != nil {
4853
fmt.Printf("Error: %s\n", err.Error())
4954
os.Exit(1)
5055
}

0 commit comments

Comments
 (0)