{"record":{"id":"247f6e1566cbea39","repo":"gitbutlerapp/gitbutler","slug":"failed-to-create-pull-request-status-error-t","errorCode":null,"errorMessage":"Failed to create pull request: {status} - {error_text}","messagePattern":"Failed to create pull request: (.+?) - (.+?)","errorType":"http","errorClass":"HttpStatusError","httpStatus":null,"severity":"error","filePath":"crates/but-bitbucket/src/client.rs","lineNumber":275,"sourceCode":"            close_source_branch: true,\n            source,\n            destination: DestinationBody {\n                branch: BranchBody {\n                    name: params.target_branch,\n                },\n            },\n            reviewers: reviewer_account_ids\n                .iter()\n                .map(|account_id| ReviewerBody { account_id })\n                .collect(),\n        };\n\n        let response = self.client.post(&url).json(&body).send().await?;\n        if !response.status().is_success() {\n            let status = response.status();\n            let error_text = response.text().await.unwrap_or_default();\n            return Err(\n                anyhow::Error::new(HttpStatusError { status }).context(format!(\n                    \"Failed to create pull request: {status} - {error_text}\"\n                )),\n            );\n        }\n        let pr: BitbucketApiPullRequest = response.json().await?;\n        Ok(pr.into())\n    }\n\n    /// Bitbucket does not apply default reviewers to API-created pull requests,\n    /// so fetch the effective set (repository- plus project-level) minus the\n    /// author, whom Bitbucket rejects as a reviewer.\n    /// Best-effort: a failed lookup yields no reviewers.\n    async fn default_reviewers_for_new_pr(&self, workspace: &str, repo_slug: &str) -> Vec<String> {\n        #[derive(Deserialize)]\n        struct DefaultReviewer {\n            #[serde(default)]\n            user: Option<BitbucketApiUser>,\n        }","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-bitbucket/src/client.rs#L257-L293","documentation":"Raised by the Bitbucket API client when a POST to create a pull request returns a non-2xx status. The error wraps `HttpStatusError` with a context string containing the HTTP status and the raw response body, so the caller sees exactly why Bitbucket rejected the PR creation.","triggerScenarios":"Calling `create_pull_request` -> `send_pr_create` when Bitbucket responds with 400 (invalid PR payload), 401/403 (bad token or insufficient scope), 404 (wrong workspace/repo slug), or 429/5xx (server-side issues).","commonSituations":"Stale or revoked Bitbucket app password/API token; missing `write:pullrequest:bitbucket` scope; typo'd workspace or repo slug; source or destination branch name that does not exist or contains invalid characters; Bitbucket rate limiting during CI bursts.","solutions":["Read the `error_text` in the context message — Bitbucket includes the field-level validation reason there.","Verify the token has the `write:pullrequest:bitbucket` scope and has not expired.","Confirm the workspace/repo slug and that both the source and destination branches exist on the remote.","If the status is 429 or 5xx, wait and retry the PR creation."],"exampleFix":"// before\nmatch client.create_pull_request(&title, &head, &base).await {\n    Err(e) => panic!(\"{e}\"),\n    Ok(pr) => println!(\"{}\", pr.url),\n}\n// after\nmatch client.create_pull_request(&title, &head, &base).await {\n    Err(e) if e.to_string().contains(\"400\") => eprintln!(\"Invalid PR payload: {e:#}\"),\n    Err(e) => eprintln!(\"PR creation failed: {e:#}\"),\n    Ok(pr) => println!(\"{}\", pr.url),\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight: verify token can see the repo and branches exist\nlet head_ok = client.repo_exists(workspace, repo_slug).await?;\nlet base_ok = client.branch_exists(workspace, repo_slug, base).await?;","typeGuard":null,"tryCatchPattern":"match client.create_pull_request(&title, &head, &base).await {\n    Err(e) if e.to_string().contains(\"429\") => backoff_and_retry().await,\n    Err(e) => log::error!(\"PR create failed: {e:#}\"),\n    Ok(pr) => Ok(pr),\n}","preventionTips":["Grant the token the `write:pullrequest:bitbucket` scope.","Validate branch names and workspace/repo slugs before calling.","Handle 429/5xx with exponential backoff in CI."],"tags":["bitbucket","http","api","pull-request"],"backgroundTag":"http-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"}