Skip to content

Commit b0b0c3c

Browse files
fix(backend): abort GitLab sync on non-404 API errors to prevent repo deletion (#1039)
* fix(backend): abort GitLab sync on non-404 API errors to prevent repo deletion Previously, any HTTP error from the GitLab API (including 500s) was converted to a warning and the sync continued with a partial repo list. This caused the database reconciliation to delete repos from the failed group/user/project. Now only 404 errors are treated as warnings (resource not found or no access); all other errors abort the sync so the database is left untouched. Fixes #1029 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: update CHANGELOG for #1039 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bdab4b7 commit b0b0c3c

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Fixed line numbers being selectable in Safari in the lightweight code highlighter. [#1037](https://github.com/sourcebot-dev/sourcebot/pull/1037)
12+
- Fixed GitLab sync deleting repos when the API returns a non-404 error (e.g. 500) during group/user/project fetch. [#1039](https://github.com/sourcebot-dev/sourcebot/pull/1039)
1213

1314
### Added
1415
- Added optional copy button to the lightweight code highlighter (`isCopyButtonVisible` prop), shown on hover. [#1037](https://github.com/sourcebot-dev/sourcebot/pull/1037)

packages/backend/src/gitlab.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
9696
Sentry.captureException(e);
9797
logger.error(`Failed to fetch projects for group ${group}.`, e);
9898

99-
const status = e?.cause?.response?.status;
100-
if (status !== undefined) {
101-
const warning = `GitLab API returned ${status}`
99+
if (e?.cause?.response?.status === 404) {
100+
const warning = `Group ${group} not found or no access`;
102101
logger.warn(warning);
103102
return {
104103
type: 'warning' as const,
105104
warning
106-
}
105+
};
107106
}
108107

109-
logger.error("No API response status returned");
110108
throw e;
111109
}
112110
}));
@@ -136,17 +134,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
136134
Sentry.captureException(e);
137135
logger.error(`Failed to fetch projects for user ${user}.`, e);
138136

139-
const status = e?.cause?.response?.status;
140-
if (status !== undefined) {
141-
const warning = `GitLab API returned ${status}`
137+
if (e?.cause?.response?.status === 404) {
138+
const warning = `User ${user} not found or no access`;
142139
logger.warn(warning);
143140
return {
144141
type: 'warning' as const,
145142
warning
146-
}
143+
};
147144
}
148145

149-
logger.error("No API response status returned");
150146
throw e;
151147
}
152148
}));
@@ -174,17 +170,15 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig) =
174170
Sentry.captureException(e);
175171
logger.error(`Failed to fetch project ${project}.`, e);
176172

177-
const status = e?.cause?.response?.status;
178-
if (status !== undefined) {
179-
const warning = `GitLab API returned ${status}`
173+
if (e?.cause?.response?.status === 404) {
174+
const warning = `Project ${project} not found or no access`;
180175
logger.warn(warning);
181176
return {
182177
type: 'warning' as const,
183178
warning
184-
}
179+
};
185180
}
186181

187-
logger.error("No API response status returned");
188182
throw e;
189183
}
190184
}));

0 commit comments

Comments
 (0)