gitbutlerapp/gitbutler · error
PR number must be greater than 0
Error message
PR number must be greater than 0
What it means
Parameter validation in set_pull_request_draft_state: the caller passed a pr_number of zero or below. GitHub PR numbers are positive integers, so the request is rejected client-side before any network call is made.
Solutions
- Fix the caller to pass the real PR number (> 0)
- Validate/persist the pr_number where it is produced instead of defaulting to 0
- Parse PR numbers from strings with proper error propagation (e.g. str::parse::<u64>() with ?) rather than unwrap_or(0)
Example fix
// before
let pr_number = url.rsplit('/').next().and_then(|s| s.parse().ok()).unwrap_or(0);
// after
let pr_number: u64 = url.rsplit('/').next().unwrap().parse()?; Defensive patterns
Strategy: validation
Validate before calling
fn validate_pr_number(pr_number: i64) -> anyhow::Result<u64> {
u64::try_from(pr_number).ok().filter(|n| *n > 0).context("PR number must be greater than 0")
} Prevention
- Never default PR numbers with unwrap_or(0); propagate parse errors
- Validate pr_number at the boundary where it is parsed from strings/URLs
- Keep pr_number as a non-zero type (u64 with explicit checks) in your config structs
When it happens
Trigger: Calling set_pull_request_draft_state with SetPullRequestDraftStateParams whose pr_number is 0, negative, or an uninitialized/default value (e.g. an unwrap_or(0) upstream).
Common situations: Parsing a PR number from a string or URL that failed and defaulted to 0; a caller passing Option::unwrap_or_default; off-by-one when deriving the number from a branch index.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Invalid prompt: must be a non-empty array
- Aborting due to empty branch name
- Aborting due to empty
- API returned version
- At least one review number is required
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/65d9f1a748ccf743.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-github/src/client.rs:1504
.and_then(|value| {
value
.get("message")
.and_then(|m| m.as_str().map(String::from))
})
.unwrap_or(body);
bail!("GitHub refused the merge ({status}): {reason}");
}
Ok(())
}
/// Set the draftiness of a PR.
pub async fn set_pull_request_draft_state(
&self,
params: &SetPullRequestDraftStateParams<'_>,
) -> Result<()> {
if params.pr_number <= 0 {
bail!("PR number must be greater than 0");
}
let pull_request_id = self
.get_pull_request_node_id(params.owner, params.repo, params.pr_number)
.await?;
if params.draft {
self.set_pull_request_to_draft(&pull_request_id).await
} else {
self.set_pull_request_to_ready_for_review(&pull_request_id)
.await
}
}
async fn set_pull_request_to_ready_for_review(
&self,
pull_request_id: &PullRequestNodeId,
) -> Result<()> {View on GitHub (pinned to 58e5313667)