fix(backend): don't crash Gitea sync when a repo fetch returns a null body#1416
Open
rachit367 wants to merge 2 commits into
Open
fix(backend): don't crash Gitea sync when a repo fetch returns a null body#1416rachit367 wants to merge 2 commits into
rachit367 wants to merge 2 commits into
Conversation
… body
When repoGet fails mid-body (e.g. ERR_STREAM_PREMATURE_CLOSE) gitea-js
resolves with { data: null, error } instead of throwing. getRepos wrapped
that as [null], which flowed into allRepos and crashed the whole sync at
allRepos.filter(repo => repo.full_name !== undefined) on null.full_name.
Treat a null response body as a per-repo warning (like the 404 path) so a
single failed fetch is skipped instead of failing the connection, and
harden the top-level filter against null. Also drops a redundant
duplicate full_name filter.
Fixes sourcebot-dev#1404
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR fixes a Gitea connection sync crash that occurred when a repository fetch returned an empty response body. It adds null/undefined guards in ChangesGitea sync crash fix
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant getGiteaReposFromConfig
participant getRepos
participant giteaApi
participant logger
getGiteaReposFromConfig->>getRepos: request repo list
getRepos->>giteaApi: repos.repoGet(org, repo)
giteaApi-->>getRepos: response (data: null, error)
getRepos->>logger: warn(repo context, error)
getRepos-->>getGiteaReposFromConfig: warning result (skip repo)
getGiteaReposFromConfig->>getGiteaReposFromConfig: filter allRepos (skip null/missing full_name)
getGiteaReposFromConfig->>logger: warn(repo?.id)
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1404
Problem
Syncing repositories from a (self-hosted) Gitea instance can crash the entire connection sync with:
When
api.repos.repoGet()fails while reading the response body (e.g.ERR_STREAM_PREMATURE_CLOSE),gitea-jsdoes not throw — it resolves with{ data: null, error: {...} }. IngetRepos(packages/backend/src/gitea.ts) that response is wrapped asdata: [response.data], sonullis pushed intoallRepos. The top-levelallRepos.filter(repo => repo.full_name !== undefined)then dereferencesnull.full_nameand fails the whole sync — one transient per-repo error takes down every repo in the connection.Fix
getRepos, ifresponse.datais null, emit a per-repo warning (mirroring the existing 404 handling) instead of returning a null "valid" repo, so a single failed fetch is skipped and the rest of the connection still syncs.null/undefinedentries defensively, and collapse the redundant duplicatefull_namefilter into one.This doesn't attempt the underlying stream workaround (the reporter's
Accept-Encoding: identitypatch) — that's a separate networking concern; this PR makes the sync resilient to the failure rather than papering over the transport.Tests
Added
gitea.test.ts:Both pass.
tsc --noEmitis clean for the backend package.Summary by CodeRabbit