{"record":{"id":"9127b754c4f59464","repo":"gitbutlerapp/gitbutler","slug":"failed-to-create-merge-request-status-error","errorCode":null,"errorMessage":"Failed to create merge request: {status} - {error_text}","messagePattern":"Failed to create merge request: (.+?) - (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-gitlab/src/client.rs","lineNumber":348,"sourceCode":"            None\n        };\n\n        let title = update_draft_state_in_title(params.title, params.draft);\n\n        let body = CreateMergeRequestBody {\n            title: &title,\n            description: params.body,\n            source_branch: params.source_branch,\n            target_branch: params.target_branch,\n            target_project_id,\n        };\n\n        let response = self.client.post(&url).json(&body).send().await?;\n\n        if !response.status().is_success() {\n            let status = response.status();\n            let error_text = response.text().await.unwrap_or_default();\n            bail!(\"Failed to create merge request: {status} - {error_text}\");\n        }\n\n        let mr: GitLabMergeRequest = response.json().await?;\n        Ok(mr.into())\n    }\n\n    pub async fn get_merge_request(\n        &self,\n        project_id: GitLabProjectId,\n        mr_iid: i64,\n    ) -> Result<MergeRequest> {\n        let url = format!(\n            \"{}/projects/{}/merge_requests/{}\",\n            self.base_url, project_id, mr_iid\n        );\n\n        let response = self.client.get(&url).send().await?;\n","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-gitlab/src/client.rs#L330-L366","documentation":"GitLab rejected the merge-request creation POST with a non-success HTTP status. The client embeds both the status code and the raw response body so the caller can see GitLab's exact validation or authorization message.","triggerScenarios":"Calling create_merge_request when POST /projects/{id}/merge_requests returns 4xx/5xx — 401 bad token, 403 insufficient permissions, 400/422 validation failures (missing source_branch/target_branch/title, branches with no diff, duplicate open MR), 404 wrong project id.","commonSituations":"Source and target branch identical or source has no commits beyond target (422 'nothing to merge'); an open MR already exists for the same branches; project ID vs path confusion; token scope too narrow; pushing to a fork but creating the MR against the wrong project.","solutions":["Read the `{status} - {error_text}` payload — GitLab states the exact validation failure.","Ensure the source branch is pushed and differs from the target (has a diff).","Check for an existing open MR between the same source and target branches and reuse it instead.","Verify the access token is valid and has api scope with write access to the project.","Confirm the project ID (numeric) and target branch names are correct."],"exampleFix":"// before\nlet mr = gitlab.create_merge_request(project_id, &source, &target, &title).await?;\n\n// after\nif let Err(e) = gitlab.create_merge_request(project_id, &source, &target, &title).await {\n    if e.to_string().contains(\"422\") && e.to_string().contains(\"nothing to merge\") {\n        return Ok(None); // no diff — skip MR creation\n    }\n    return Err(e);\n}","handlingStrategy":"try-catch","validationCode":"// validate inputs before creating the MR\nanyhow::ensure!(source_branch != target_branch, \"source and target branches must differ\");\nanyhow::ensure!(!title.trim().is_empty(), \"MR title required\");\n// optionally: confirm source branch is pushed and has a diff vs target","typeGuard":null,"tryCatchPattern":"match gitlab.create_merge_request(project_id, &source, &target, &title).await {\n    Ok(mr) => mr,\n    Err(e) if e.to_string().contains(\"422\") && e.to_string().contains(\"open merge request\") => {\n        find_existing_mr(project_id, &source, &target).await? // reuse instead\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check for an existing open MR between the same branches before creating one.","Push the source branch and verify it has a diff before calling.","Validate the token's api scope and project write access.","Use the numeric project ID, not the path, unless the API variant expects it."],"tags":["gitlab","api","http","merge-request"],"backgroundTag":"api-error-response","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}