Skip to content

Error when calling Repository.ListFiles #127

Open
@twopelu

Description

@twopelu

Hello,

I'm trying to list files in my BitBucket repository but I get an error.

My module setup is:

go 1.16

require github.com/ktrysmt/go-bitbucket v0.9.9 // indirect

The test code is as follows:

(just change the "my" variables for your user, pass, owner, repo, etc.)

package lib

import (
	"fmt"
	"testing"
	"github.com/ktrysmt/go-bitbucket"
)

func Test(t *testing.T) {
	c := bitbucket.NewBasicAuth("myuser", "mypass")

	fmt.Println("List repos...")
	optr := &bitbucket.RepositoriesOptions{
		Owner: "myowner",
		Role:  "",
	}

	repos, err1 := c.Repositories.ListForAccount(optr)
	if err1 != nil {
		fmt.Println("Error listing repos:", err1)
		panic(err1)
	}
	fmt.Println("List number of repos:", repos.Size)

	for _, repo := range repos.Items {
		fmt.Println("List repo with name:", repo.Name)
	}

	repong6 := repos.Items[4] // a public repo to test

	fmt.Println("List files in repo:", repong6.Name, "...")
	optrf := &bitbucket.RepositoryFilesOptions{
		Owner:    "myowner",
		RepoSlug: "myslug",
		Ref:      "myref",
		Path:     "mypath",
	}

	files, err2 := repong6.ListFiles(optrf)
	if err2 != nil {
		fmt.Println("Error listing files:", err2)
		panic(err2)
	}
	fmt.Println("List number of files:", len(files))

	for _, file := range files {
		fmt.Println("List file with name:", file.Path)
	}
}

The error happens in the line:

files, err2 := repong6.ListFiles(optrf)

--- FAIL: Test (0.74s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x58 pc=0x60ccca]

goroutine 6 [running]:
testing.tRunner.func1.2(0x648a00, 0x88cb70)
        C:/Program Files/Go/src/testing/testing.go:1144 +0x345
testing.tRunner.func1(0xc00002d080)
        C:/Program Files/Go/src/testing/testing.go:1147 +0x4b6
panic(0x648a00, 0x88cb70)
        C:/Program Files/Go/src/runtime/panic.go:965 +0x1c7
github.com/ktrysmt/go-bitbucket.(*Client).requestUrl(0x0, 0xc0002bc420, 0x5f, 0x0, 0x0, 0x0, 0x5f, 0xc00014a180)
        C:/Users/dani/go/pkg/mod/github.com/ktrysmt/[email protected]/client.go:376 +0x8a
github.com/ktrysmt/go-bitbucket.(*Repository).ListFiles(0xc00004fd00, 0xc00004fc60, 0xc00004fc30, 0x3, 0x3, 0x29, 0x0)
        C:/Users/dani/go/pkg/mod/github.com/ktrysmt/[email protected]/repository.go:220 +0x17f
github.com/twopelu/hulk/lib.Test(0xc00002d080)
        D:/DANI/go/hulk/lib/lib_test.go:40 +0x4e6
testing.tRunner(0xc00002d080, 0x6b5f50)
        C:/Program Files/Go/src/testing/testing.go:1194 +0xef
created by testing.(*T).Run
        C:/Program Files/Go/src/testing/testing.go:1239 +0x2b3
exit status 2
FAIL    github.com/twopelu/hulk/lib     0.860s

I have checked that the options and the url are ok, and also that it works when called from the browser:

https://github.com/ktrysmt/go-bitbucket/blob/v0.9.9/repository.go#L220

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src

Example URL: https://api.bitbucket.org/2.0/repositories/myuser/myslug/src/myref/mypath

But when I call it from code it returns "invalid memory address or nil pointer dereference", any help please?

Many thanks,

Dani

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions