fix(gitea): guard against empty response in ListContents fallback
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 22s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 26s
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 40s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 58s
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 22s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 26s
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 40s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 58s
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.
This commit is contained in:
@@ -458,6 +458,10 @@ func (c *Client) ListContents(ctx context.Context, owner, repo, path string) ([]
|
|||||||
if err2 := json.Unmarshal(body, &single); err2 != nil {
|
if err2 := json.Unmarshal(body, &single); err2 != nil {
|
||||||
return nil, fmt.Errorf("parse contents JSON: %w", err)
|
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}
|
entries = []ContentEntry{single}
|
||||||
}
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user