From 2bf5e956a6054c84b819b02b9bdbc87e132b1a86 Mon Sep 17 00:00:00 2001 From: Jarryd Tilbrook Date: Fri, 2 Aug 2024 15:51:08 +0800 Subject: [PATCH] Check for nil pointer --- pkg/cmd/factory/factory.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/factory/factory.go b/pkg/cmd/factory/factory.go index c22ce0fc..1d0329af 100644 --- a/pkg/cmd/factory/factory.go +++ b/pkg/cmd/factory/factory.go @@ -23,15 +23,19 @@ 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) + var httpClient *http.Client + if err == nil { + httpClient = tk.Client() + } return &Factory{ Config: conf, GitRepository: repo, - GraphQLClient: graphql.NewClient(config.DefaultGraphQLEndpoint, tk.Client()), - HttpClient: tk.Client(), + GraphQLClient: graphql.NewClient(config.DefaultGraphQLEndpoint, httpClient), + HttpClient: httpClient, OpenAIClient: openai.NewClient(conf.GetOpenAIToken()), - RestAPIClient: buildkite.NewClient(tk.Client()), + RestAPIClient: buildkite.NewClient(httpClient), Version: version, } }