McKael / madonctl

CLI client for the Mastodon social network API
MIT License
194 stars 9 forks source link

nil context when trying to `oauth2` #12

Closed schas002 closed 6 years ago

schas002 commented 6 years ago

Each time I try to register via madonctl oauth2, I get a nil context error:

PC@PC-comp MINGW64 ~/Desktop
$ madonctl oauth2
Registered new application.
Visit the URL for the auth dialog:
https://botsin.space/oauth/authorize?access_type=offline&client_id=[*snip*]&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=read+write+follow&state=state
Enter code: [*snip*]
panic: nil context

goroutine 1 [running]:
net/http.(*Request).WithContext(0xc042230300, 0x0, 0x0, 0xc042014240)
        C:/Go/src/net/http/request.go:327 +0x1c9
golang.org/x/net/context/ctxhttp.Do(0x0, 0x0, 0xb5dd00, 0xc042230300, 0x40, 0xc042002320, 0xc042230300)
        C:/Users/PC/go/src/golang.org/x/net/context/ctxhttp/ctxhttp.go:30 +0x5d
golang.org/x/oauth2/internal.RetrieveToken(0x0, 0x0, 0xc04200e200, 0x40, 0xc04200e240, 0x40, 0xc0420106c0, 0x20, 0xc0421744b0, 0x0, ...)
        C:/Users/PC/go/src/golang.org/x/oauth2/internal/token.go:192 +0x219
golang.org/x/oauth2.retrieveToken(0x0, 0x0, 0xc042232380, 0xc0421744b0, 0xc042236798, 0x0, 0x0)
        C:/Users/PC/go/src/golang.org/x/oauth2/token.go:153 +0x90
golang.org/x/oauth2.(*Config).Exchange(0xc042232380, 0x0, 0x0, 0xc04200e300, 0x40, 0xc0420106c0, 0x20, 0x0)
        C:/Users/PC/go/src/golang.org/x/oauth2/oauth2.go:179 +0x243
github.com/McKael/madon.(*Client).LoginOAuth2(0xc04207cc60, 0xc04200e300, 0x40, 0xb4a460, 0x3, 0x3, 0x1, 0x1, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madon/login.go:120 +0x1f8
github.com/McKael/madonctl/cmd.oAuth2ExchangeCode(0xc042067cc8, 0x1, 0x1, 0x1, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:84 +0x8a
github.com/McKael/madonctl/cmd.oAuth2Interactive(0xb7bb28, 0x0, 0x0, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:117 +0x292
github.com/McKael/madonctl/cmd.glob..func20(0xb54000, 0xb7bb28, 0x0, 0x0, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:26 +0x46
github.com/spf13/cobra.(*Command).execute(0xb54000, 0xb7bb28, 0x0, 0x0, 0xb54000, 0xb7bb28)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:698 +0x481
github.com/spf13/cobra.(*Command).ExecuteC(0xb52ac0, 0xc042067f48, 0x1, 0x1)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:783 +0x315
github.com/spf13/cobra.(*Command).Execute(0xb52ac0, 0xc042067f70, 0x7f50ab)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:736 +0x32
main.main()
        C:/Users/PC/go/src/github.com/McKael/madonctl/main.go:28 +0x34
McKael commented 6 years ago

Thanks, I'll check that.

Is it with madonctl 2.0.0-dev?

schas002 commented 6 years ago

@McKael Sure:

PC@PC-comp MINGW64 ~/Desktop
$ madonctl version | grep '2.0.0-dev'
This is madonctl version 2.0.0-dev (using madon library version 2.0.0-dev).

PC@PC-comp MINGW64 ~/Desktop
$ $?
bash: 0: command not found
schas002 commented 6 years ago

Wait nevermind again, it happens even on a fresh config:

PC@PC-comp MINGW64 ~/Desktop
$ mv ~/.config/madonctl/madonctl.yaml{,.bak}

PC@PC-comp MINGW64 ~/Desktop
$ madonctl oauth2 -i botsin.space
Registered new application.
Visit the URL for the auth dialog:
https://botsin.space/oauth/authorize?access_type=offline&client_id=[*snip*]&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=read+write+follow&state=state
Enter code: [*snip*]
panic: nil context

goroutine 1 [running]:
net/http.(*Request).WithContext(0xc042230300, 0x0, 0x0, 0xc042014240)
        C:/Go/src/net/http/request.go:327 +0x1c9
golang.org/x/net/context/ctxhttp.Do(0x0, 0x0, 0xb5dd00, 0xc042230300, 0x40, 0xc042002340, 0xc042230300)
        C:/Users/PC/go/src/golang.org/x/net/context/ctxhttp/ctxhttp.go:30 +0x5d
golang.org/x/oauth2/internal.RetrieveToken(0x0, 0x0, 0xc04200e200, 0x40, 0xc04200e240, 0x40, 0xc0420106c0, 0x20, 0xc0421704b0, 0x0, ...)
        C:/Users/PC/go/src/golang.org/x/oauth2/internal/token.go:192 +0x219
golang.org/x/oauth2.retrieveToken(0x0, 0x0, 0xc042232380, 0xc0421704b0, 0xc042236798, 0x0, 0x0)
        C:/Users/PC/go/src/golang.org/x/oauth2/token.go:153 +0x90
golang.org/x/oauth2.(*Config).Exchange(0xc042232380, 0x0, 0x0, 0xc04200e300, 0x40, 0xc0420106c0, 0x20, 0x0)
        C:/Users/PC/go/src/golang.org/x/oauth2/oauth2.go:179 +0x243
github.com/McKael/madon.(*Client).LoginOAuth2(0xc04207ed20, 0xc04200e300, 0x40, 0xb4a460, 0x3, 0x3, 0x1, 0x1, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madon/login.go:120 +0x1f8
github.com/McKael/madonctl/cmd.oAuth2ExchangeCode(0xc042067cc8, 0x1, 0x1, 0x1, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:84 +0x8a
github.com/McKael/madonctl/cmd.oAuth2Interactive(0xc0420dcf80, 0x0, 0x2, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:117 +0x292
github.com/McKael/madonctl/cmd.glob..func20(0xb54000, 0xc0420dcf80, 0x0, 0x2, 0x0, 0x0)
        C:/Users/PC/go/src/github.com/McKael/madonctl/cmd/oauth2.go:26 +0x46
github.com/spf13/cobra.(*Command).execute(0xb54000, 0xc0420dcf20, 0x2, 0x2, 0xb54000, 0xc0420dcf20)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:698 +0x481
github.com/spf13/cobra.(*Command).ExecuteC(0xb52ac0, 0xc042067f48, 0x1, 0x1)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:783 +0x315
github.com/spf13/cobra.(*Command).Execute(0xb52ac0, 0xc042067f70, 0x7f50ab)
        C:/Users/PC/go/src/github.com/spf13/cobra/command.go:736 +0x32
main.main()
        C:/Users/PC/go/src/github.com/McKael/madonctl/main.go:28 +0x34
McKael commented 6 years ago

I can reproduce, I'll fix it, thanks.

McKael commented 6 years ago

@schas002 Should be OK now (works for me...)!

Don't forget to upgrade the madon library.