From c27dfd0f08ef4b5799e8ef45030ab53036c17128 Mon Sep 17 00:00:00 2001 From: Rodin Date: Mon, 11 May 2026 07:47:03 -0700 Subject: [PATCH] fix(gitea): guard against empty response in ListContents fallback Add defensive check for empty Name and Path fields when unmarshaling a single ContentEntry in the fallback path. While Gitea API won't return empty objects for valid file paths, this guard: - Explicitly documents the invariant we expect - Catches potential API behavior changes early - Costs nothing at runtime Addresses [MINOR] from sonnet-review-bot on PR #74. --- gitea/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gitea/client.go b/gitea/client.go index 45389a6..55835ac 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -458,6 +458,10 @@ func (c *Client) ListContents(ctx context.Context, owner, repo, path string) ([] if err2 := json.Unmarshal(body, &single); err2 != nil { return nil, fmt.Errorf("parse contents JSON: %w", err) } + // Guard against empty/malformed responses + if single.Name == "" && single.Path == "" { + return nil, fmt.Errorf("parse contents JSON: empty response for path %q", path) + } entries = []ContentEntry{single} } return entries, nil