Skip to content

Skip Gitea SDK version probe to avoid nil client on unreachable hosts#59

Merged
andrew merged 1 commit intomainfrom
gitea-nil-client
Apr 13, 2026
Merged

Skip Gitea SDK version probe to avoid nil client on unreachable hosts#59
andrew merged 1 commit intomainfrom
gitea-nil-client

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 13, 2026

Closes #58.

gitea.NewClient calls /api/v1/version during construction to check the server is at least 1.11. When that request fails (DNS error, connection refused, timeout) it returns (nil, err). We were discarding the error at gitea/gitea.go:27 and storing the nil client, so the first real API call would dereference nil and panic.

The fix passes gitea.SetGiteaVersion("") which sets ignoreVersion = true in the SDK, making the version check a no-op. NewClient then never hits the network and never returns nil. Connection failures now surface as ordinary errors on the first real request:

Error: listing pull requests: Get "https://gitea.example.com/api/v1/repos/o/r/pulls?...": dial tcp: lookup gitea.example.com: no such host

This also removes a wasted round-trip on every invocation, since New is called at startup for the default codeberg.org registration regardless of which forge the user is actually targeting.

The first test reproduces the panic by closing an httptest server before calling into the forge. The second confirms construction no longer hits the version endpoint.

@andrew andrew merged commit 95c191e into main Apr 13, 2026
4 checks passed
@andrew andrew deleted the gitea-nil-client branch April 13, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when origin points to an unreachable Gitea host

1 participant