travelagent-core 1.10.2

Core library for travelagent code review tool
Documentation
use thiserror::Error;

/// Record of a discussion that was successfully posted before a later step
/// in `submit_review` failed. Attached to [`TrvError::PartialReviewSubmit`]
/// so callers can inform the user which inline comments made it through
/// and (in future) resume or clean up.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PostedDiscussion {
    /// Index into the original `NewReview.comments` vector.
    pub index: usize,
    /// Server-assigned note id of the root note of the created discussion.
    pub note_id: u64,
    /// Server-assigned discussion/thread id.
    pub discussion_id: String,
}

#[derive(Error, Debug)]
pub enum TrvError {
    #[error("Git error: {0}")]
    Git(#[from] git2::Error),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("JSON serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    #[error("Not a repository")]
    NotARepository,

    #[error(
        "This repository uses reftable ref storage, which is not yet supported by libgit2. Re-init with `git init --ref-format=files` or wait for libgit2 reftable support."
    )]
    ReftableRepository,

    #[error("No changes to review")]
    NoChanges,

    #[error("No comments to export - skipping copy")]
    NoComments,

    #[error("Review session corrupted: {0}")]
    CorruptedSession(String),

    #[error("Clipboard error: {0}")]
    Clipboard(String),

    #[error("VCS command failed: {0}")]
    VcsCommand(String),

    #[error("Unsupported operation: {0}")]
    UnsupportedOperation(String),

    #[error("Forge API error: {0}")]
    ForgeApi(String),

    #[error("Authentication failed: {0}")]
    AuthError(String),

    #[error("Rate limited")]
    RateLimited,

    #[error("Resource not found: {0}")]
    NotFound(String),

    /// Returned by `ForgeBackend::submit_review` when the backend posts review
    /// artifacts in multiple non-atomic steps (e.g. GitLab) and a later step
    /// fails after earlier ones succeeded. Carries the list of discussions
    /// that were posted before the failure and whether an approval was
    /// attempted, so callers can report progress and decide whether to
    /// retry or reconcile.
    #[error(
        "{} of {total} comments posted{approval}; remaining not submitted due to: {cause}",
        posted.len(),
        total = posted.len() + remaining,
        approval = if *approval_posted { " (approval posted)" } else { "" }
    )]
    PartialReviewSubmit {
        posted: Vec<PostedDiscussion>,
        /// Number of comments that were not attempted or failed.
        remaining: usize,
        /// True if the approval request succeeded before the failure.
        approval_posted: bool,
        /// Underlying error that caused the submit to abort.
        #[source]
        cause: Box<TrvError>,
    },
}

pub type Result<T> = std::result::Result<T, TrvError>;