Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(gitlab): give the project not found error a next step (#108180)

Tom Owers99b251b6c4fe
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
index 5b0166a53693..6027efd9d0ea 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
@@ -30,6 +30,12 @@ PROJECT_REF_ERROR = (
"PostHog couldn't read a project from that value. Enter group/project (for example, "
"mygroup/myproject), the numeric project ID, or the project's GitLab URL."
)
+# GitLab answers 404 both for a project that doesn't exist and for one the token can't see, so the
+# message has to name both next steps.
+PROJECT_NOT_ACCESSIBLE_ERROR = (
+ "Project '{project}' not found or not accessible with this token. Check the spelling and that "
+ "your token has read access to the project."
+)
class GitLabRetryableError(Exception):
@@ -261,7 +267,7 @@ def validate_credentials(
return False, "Invalid GitLab personal access token"
if response.status_code == 404:
- return False, f"Project '{project}' not found or not accessible with this token"
+ return False, PROJECT_NOT_ACCESSIBLE_ERROR.format(project=project)
if response.status_code == 403:
# GitLab returns a raw OAuth-style JSON body (e.g. {"error":"insufficient_scope",...}) here,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
index 1655f7e59c1d..292e50dfdb59 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
@@ -245,7 +245,9 @@ class TestValidateCredentials:
[
(200, True, None),
(401, False, "Invalid GitLab personal access token"),
- (404, False, "not found"),
+ # A 404 can't tell a missing project from one the token can't see, so the message has to
+ # carry the next step rather than dead-ending on "not accessible".
+ (404, False, "not accessible with this token. Check the spelling and that your token has read access"),
],
)
def test_status_code_mapping(self, status_code, expected_valid, expected_msg_substr):