cli icon indicating copy to clipboard operation
cli copied to clipboard

panic following Development section in README

Open mmlb opened this issue 1 year ago • 1 comments

I'm trying out the cli locally and can't get past a nil deref panic early in factory.go. I've followed the README and see the following:

[11:14:12]-[~/t/b/b/cli]-[manny@c3mv18nix]
git status
On branch 3.x
Your branch is up to date with 'origin/3.x'.

nothing to commit, working tree clean
[11:14:14]-[~/t/b/b/cli]-[manny@c3mv18nix]
git rev-parse HEAD
f178e56e753ef45bf80f9bdf09e49b3546e4fb07
[11:14:16]-[~/t/b/b/cli]-[manny@c3mv18nix]
echo $BUILDKITE_GRAPHQL_TOKEN | head -c 7
bkua_f7⏎                                                                                                                                                                              [11:14:19]-[~/t/b/b/cli]-[manny@c3mv18nix]
go generate
Generating GraphQL code
[11:14:21]-[~/t/b/b/cli]-[manny@c3mv18nix]
go run cmd/bk/main.go --help
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x903056]

goroutine 1 [running]:
github.com/buildkite/go-buildkite/v3/buildkite.NewClient(0xc00024a690)
	/home/manny/.cache/go/pkg/mod/github.com/buildkite/go-buildkite/[email protected]/buildkite/buildkite.go:105 +0x536
github.com/buildkite/cli/v3/pkg/cmd/factory.New({0xb46d94, 0x3})
	/home/manny/t/bk/buildkite/cli/pkg/cmd/factory/factory.go:34 +0x3db
main.mainRun()
	/home/manny/t/bk/buildkite/cli/cmd/bk/main.go:20 +0x25
main.main()
	/home/manny/t/bk/buildkite/cli/cmd/bk/main.go:14 +0x13
exit status 2

Adding in a little bit of debug code:

diff --git a/pkg/cmd/factory/factory.go b/pkg/cmd/factory/factory.go
index c22ce0f..1b2c9dc 100644
--- a/pkg/cmd/factory/factory.go
+++ b/pkg/cmd/factory/factory.go
@@ -23,7 +23,10 @@ type Factory struct {
 func New(version string) *Factory {
 	repo, _ := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true, EnableDotGitCommonDir: true})
 	conf := config.New(nil, repo)
-	tk, _ := buildkite.NewTokenConfig(conf.APIToken(), false)
+	tk, err := buildkite.NewTokenConfig(conf.APIToken(), false)
+	if err != nil {
+		panic(err)
+	}
 
 	return &Factory{
 		Config:        conf,

I get the following output:

go run cmd/bk/main.go --help
panic: Invalid token, empty string supplied

goroutine 1 [running]:
github.com/buildkite/cli/v3/pkg/cmd/factory.New({0xb46d94, 0x3})
	/home/manny/t/bk/buildkite/cli/pkg/cmd/factory/factory.go:28 +0x4d3
main.mainRun()
	/home/manny/t/bk/buildkite/cli/cmd/bk/main.go:20 +0x25
main.main()
	/home/manny/t/bk/buildkite/cli/cmd/bk/main.go:14 +0x13
exit status 2

looks like the env var is not being picked up.

mmlb avatar Jul 25 '24 15:07 mmlb

Oh nice find @mmlb 👍

I think this is both an error in the docs as well as a bug in the code.

That env var is actually only meant for the generate step. The bk CLI is configured through a file with bk configure. But it still shouldn't be causing a panic like this anyway. We'll take a look into it

jradtilbrook avatar Jul 26 '24 00:07 jradtilbrook