ktrysmt/go-bitbucket

ListTags in repository.go throws SIGSEGV panic

paranoidd opened this issue · 7 comments

Hello!

First of all, thank you very much for your work!

I would like to note that I am a golang noob, and hopefully it is just me not understanding something :-)

I am trying to list all the repository tags for a given repo. Here's the code snippet I wrote for that:

func BitBucketImportRepositories() {
    c := bitbucket.NewBasicAuth(os.Getenv("BITBUCKET_USERNAME"), os.Getenv("BITBUCKET_PASSWORD"))

    opt := &bitbucket.RepositoriesOptions{
        Owner: config.Module.Import.Bitbucket.Organization,
    }

    repos, err := c.Repositories.ListForAccount(opt)

    if err != nil {
        log.Fatalf("Failed to fetch repositories from BitBucket! %+v", err)
    }

    for i := 0; i < len(repos.Items); i++ {
        if re.MatcherString(repos.Items[i].Slug, 0).Matches() {

            tagOpt := &bitbucket.RepositoryTagOptions{
                Owner: "myorgname",
                RepoSlug: repos.Items[i].Slug,
                Query: "",
                Sort: "",
                PageNum: 1,
                Pagelen: 100000,
                MaxDepth: 1,
            }

            log.Println(repos.Items[i].ListTags(tagOpt))
            break
        }
    }
}

Execution fails with the following error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x43e2081]

goroutine 1 [running]:
github.com/ktrysmt/go-bitbucket.(*Client).requestUrl(0x0, 0x46e56c0, 0x20, 0xc0005075d8, 0x3, 0x3, 0x404174a, 0xc000041000)
    /Users/username/go/pkg/mod/github.com/ktrysmt/go-bitbucket@v0.6.5/client.go:347 +0x81
github.com/ktrysmt/go-bitbucket.(*Repository).ListTags(0xc0006e3560, 0xc000507840, 0xc0000244b0, 0x24, 0x0)
    /Users/username/go/pkg/mod/github.com/ktrysmt/go-bitbucket@v0.6.5/repository.go:266 +0x225
main.BitBucketImportRepositories()
    /Users/username/path/cmd_import_bb.go:54 +0x397
main.main.func4(0xc00012e580)
    /Users/username/path/main.go:76 +0x25
github.com/urfave/cli.HandleAction(0x45f18c0, 0x46fd008, 0xc00012e580, 0xc00012e580, 0x0)
    /Users/username/go/pkg/mod/github.com/urfave/cli@v1.22.4/app.go:528 +0x58
github.com/urfave/cli.Command.Run(0x46d5860, 0x8, 0x0, 0x0, 0xc000244ce0, 0x1, 0x1, 0x46eee4a, 0x31, 0x0, ...)
    /Users/username/go/pkg/mod/github.com/urfave/cli@v1.22.4/command.go:174 +0x58e
github.com/urfave/cli.(*App).Run(0xc0001561c0, 0xc00000e0a0, 0x2, 0x2, 0x0, 0x0)
    /Users/username/go/pkg/mod/github.com/urfave/cli@v1.22.4/app.go:279 +0x7e8
main.main()
    /Users/username/path/main.go:82 +0x395
exit status 2

I am running go version go1.15 darwin/amd64

Is there anything I am doing wrong here? I'd appreciate any hints and directions.

Thank you!

Hmm, let me check. I will try that.
Thank you for your reporting. @paranoidd

I tried a sample code and it seems to work.
So please check the code uploaded along with go-version. @paranoidd

version: go version go1.15.3 darwin/amd64
code: https://github.com/ktrysmt/go-bitbucket/blob/master/tests/list_test.go

Hey @ktrysmt, thank you for your reply!

I am sorry if this is a noob question, but in the test you've linked, I do not see ListTags method being called. The ListForAccount method from Repositories works as expected, however when calling log.Println(repos.Items[i].ListTags(tagOpt)) it gives the panic which I listed in the initial message.

I've upgraded the go version to the same as yours and still experiencing the problem :(

ListTags

Oh I see. I will do try-and-error again. Thank you. @paranoidd

I have updated the sample code to test ListTags. Please check it. @paranoidd
https://github.com/ktrysmt/go-bitbucket/blob/master/tests/list_test.go

c : Client has a query request generator. Use it each time you call the client for each API request.

c : Client has a query request generator. Use it each time you call the client for each API request.

This was the part I was missing, got it all running.

Thank you for your help and patience!