Skip to content

Panic when origin points to an unreachable Gitea host #58

@andrew

Description

@andrew

Found while testing #57. If origin points to a Gitea-shaped domain that can't be reached, any command that calls into the Gitea backend panics instead of returning an error.

Repro:

git init
git remote add origin https://gitea.example.com/o/r.git
forge pr list

Stack:

panic: runtime error: invalid memory address or nil pointer dereference
code.gitea.io/sdk/gitea.(*Client).doRequest
    client.go:335
code.gitea.io/sdk/gitea.(*Client).ListRepoPullRequests(0x0, ...)
    pull.go:133
github.com/git-pkgs/forge/gitea.(*giteaPRService).List
    gitea/prs.go:155

The receiver on ListRepoPullRequests is 0x0 — the SDK client is nil.

Cause is gitea/gitea.go:27:

c, _ := gitea.NewClient(baseURL, opts...)
return &giteaForge{client: c, ...}

gitea.NewClient does a network call on construction to fetch the server version (unlike the GitHub and GitLab SDKs which connect lazily). When the host is unreachable it returns (nil, err) and we store the nil. Every subsequent call on the forge dereferences it.

Fix is to either check the error there, or pass gitea.SetGiteaVersion("") to skip the version probe and defer the failure to the first real request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions