gitbutlerapp/gitbutler · error

Failed to update comment

Error message

Failed to update comment: {}

What it means

This error comes from `GithubClient::update_pull_request_comment`, which PATCHes `/repos/{owner}/{repo}/issues/comments/{comment_id}` with the new markdown body. A non-success status is surfaced as this error, meaning the comment edit was rejected and no `PullRequestComment` is returned.

Solutions

  1. Read the status/details in the error message: 404 means the id is wrong or stale, 401/403 means auth.
  2. Refresh the comment id by listing the PR's issue comments before PATCHing.
  3. Verify the token has repository write access and has not expired.
  4. Confirm you are using the `issues/comments` id, not a review-comment id (`pulls/comments`).
  5. Retry after rate-limit reset if `X-RateLimit-Remaining` is 0.

Example fix

// before
client.update_pull_request_comment(owner, repo, stale_id, "edited").await?; // 404
// after
let comments = client.list_pull_request_comments(owner, repo, pr).await?;
if let Some(c) = comments.iter().find(|c| c.id == stale_id) {
    client.update_pull_request_comment(owner, repo, c.id, "edited").await?;
}
Defensive patterns

Strategy: try-catch

Validate before calling

let comments = client.list_pull_request_comments(owner, repo, pr).await?;
if !comments.iter().any(|c| c.id == comment_id) {
    return Err(anyhow!("comment {comment_id} does not exist on {owner}/{repo}#{pr}"));
}
if body.trim().is_empty() { return Err(anyhow!("comment body must not be empty")); }

Type guard

fn comment_exists(comments: &[PullRequestComment], id: i64) -> bool { comments.iter().any(|c| c.id == id) }

Try / catch

match client.update_pull_request_comment(owner, repo, comment_id, body).await {
    Ok(c) => info!("comment {} updated", c.id),
    Err(e) if e.to_string().contains("404") => warn!("comment vanished; skipping edit"),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any `update_pull_request_comment(owner, repo, comment_id, body)` call whose PATCH returns non-2xx — 404 (comment id does not exist or belongs to another repo), 403 (token lacks write or is rate-limited), 401 (expired/invalid token), 422 (invalid body).

Common situations: Editing a comment that was deleted by another user while the UI kept the old id; using an id from a review comment (different endpoint) as an issue-comment id; token lost `repo` scope after regeneration; editing on the wrong fork.

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


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/d654746b4452142e. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-github/src/client.rs:951

        #[derive(Serialize)]
        struct CommentBody<'a> {
            body: &'a str,
        }

        let url = format!(
            "{}/repos/{}/{}/issues/comments/{}",
            self.base_url, owner, repo, comment_id
        );

        let response = self
            .client
            .patch(&url)
            .json(&CommentBody { body })
            .send()
            .await?;

        if !response.status().is_success() {
            bail!(
                "Failed to update comment: {}",
                response_error(response).await
            );
        }

        let comment: GitHubIssueComment = response.json().await?;
        Ok(comment.into())
    }

    pub async fn delete_pull_request_comment(
        &self,
        owner: &str,
        repo: &str,
        comment_id: i64,
    ) -> Result<()> {
        let url = format!(
            "{}/repos/{}/{}/issues/comments/{}",
            self.base_url, owner, repo, comment_id

View on GitHub (pinned to 58e5313667)