gitbutlerapp/gitbutler · error
Failed to fetch project
Error message
Failed to fetch project: {status} - {error_text} What it means
fetch_project_by_path performs GET {base_url}/projects/{id} (URL-encoded path) and bails on any non-2xx status, embedding the status and GitLab's error body. It backs both fetch_project and fetch_project_by_numeric_id, so a 404 means GitLab could not resolve the project id/path for the authenticated token.
Solutions
- Check the embedded status: 404 means verify the project path/id and that the token's user is a member of the project.
- URL-encode the full project path with URL-encoding of `/` as %2F before interpolating into the endpoint.
- For 401/403 confirm the token has `read_api`/`api` scope and is not expired.
- Confirm base_url points at the correct GitLab instance (gitlab.com vs self-managed).
- Re-fetch the project after a rename; update stored project identifiers.
Example fix
// before
let url = format!("{}/projects/{}", self.base_url, project_path);
// after
let encoded = urlencoding::encode(project_path); // group/repo -> group%2Frepo
let url = format!("{}/projects/{}", self.base_url, encoded); Defensive patterns
Strategy: validation
Validate before calling
fn encode_project_path(path: &str) -> String {
assert!(!path.trim().is_empty(), "project path must not be empty");
urlencoding::encode(path).to_string() // group/repo -> group%2Frepo
} Try / catch
match client.fetch_project_by_path("group/repo").await {
Err(e) if e.to_string().contains("404") => {
// verify membership/path or prompt user to re-select project
}
Err(e) if e.to_string().contains("401") => {
// refresh or re-authenticate the token
}
Err(e) => return Err(e),
Ok(p) => println!("{}", p.id),
} Prevention
- URL-encode project paths (encode '/' as %2F) — especially paths containing dots
- Keep the token's scopes (read_api/api) valid and not expired
- Confirm base_url matches the instance the project lives on (gitlab.com vs self-hosted)
- Refresh cached project identifiers after namespace moves or renames
When it happens
Trigger: Project path with unencoded special characters (`/`, `.`, spaces) reaching GitLab incorrectly, project id or path not visible to the token (private project, 404), token expired/insufficient scope (401/403), typo in the project path, or project was renamed/archived/deleted.
Common situations: User configured a project URL but the token belongs to a different account; repo moved to another namespace after a company reorg; path contains dots (e.g. `group.io/repo`) that must be URL-encoded as %2F; hitting the wrong GitLab host (gitlab.com vs self-hosted).
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Failed to merge merge request
- Failed to create merge request
- Failed to disable merge request auto-merge
- Failed to enable merge request auto-merge
- Failed to set merge request draft state
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/f6f6455f6ecd6f21.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-gitlab/src/client.rs:638
struct GitLabApiPermissions {
#[serde(default)]
project_access: Option<GitLabApiAccess>,
#[serde(default)]
group_access: Option<GitLabApiAccess>,
}
#[derive(Deserialize)]
struct GitLabApiAccess {
access_level: i64,
}
let url = format!("{}/projects/{}", self.base_url, project_id);
let response = self.client.get(&url).send().await?;
if !response.status().is_success() {
let status = response.status();
let error_text = response.text().await.unwrap_or_default();
bail!("Failed to fetch project: {status} - {error_text}");
}
let project: GitLabApiProject = response.json().await?;
let access_level = project.permissions.and_then(|p| {
let project_level = p.project_access.map(|a| a.access_level);
let group_level = p.group_access.map(|a| a.access_level);
match (project_level, group_level) {
(Some(a), Some(b)) => Some(a.max(b)),
(Some(a), None) | (None, Some(a)) => Some(a),
(None, None) => None,
}
});
Ok(GitLabProject {
id: project.id,
path_with_namespace: project.path_with_namespace,
ssh_url_to_repo: project.ssh_url_to_repo,View on GitHub (pinned to 58e5313667)