Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
refactor: move message related errors from error.rs to msg.rs
Lars Wirzenius committed 2 years ago
commit a6da02f8521ad831b47b56275531233ff0343769
parent 833be8d0cc704b96db6a8468e959f7aca9a1b048
2 files changed +29 -26
modified src/error.rs
@@ -38,20 +38,4 @@ pub enum BrokerError {
    /// Default adapter is not in list of adapters.
    #[error("default adapter is not in list of adapters")]
    UnknownDefaultAdapter(String),
-

-
    /// Error retrieving context to generate trigger from BrokerEvent
-
    #[error("could not generate trigger from event")]
-
    Trigger,
-

-
    #[error(transparent)]
-
    StorageError(#[from] radicle::storage::Error),
-

-
    #[error(transparent)]
-
    RepositoryError(#[from] radicle::storage::RepositoryError),
-

-
    #[error(transparent)]
-
    CobStoreError(#[from] radicle::cob::store::Error),
-

-
    #[error(transparent)]
-
    RadicleSurfError(#[from] radicle_surf::Error),
}
modified src/msg.rs
@@ -25,7 +25,6 @@ use radicle::storage::{ReadRepository, ReadStorage};
use radicle::{patch, Profile};
use serde::{Deserialize, Serialize};

-
use crate::error::BrokerError;
use crate::filter::{is_patch_update, BrokerEvent};

/// The type of a run identifier. For maximum generality, this is a
@@ -104,7 +103,7 @@ pub enum Request {

impl Request {
    /// Create a request event to trigger a run.
-
    pub fn trigger(profile: &Profile, event: &BrokerEvent) -> Result<Self, BrokerError> {
+
    pub fn trigger(profile: &Profile, event: &BrokerEvent) -> Result<Self, MessageError> {
        let BrokerEvent::RefChanged {
            rid,
            name,
@@ -123,16 +122,16 @@ impl Request {
        let event_type: String;
        if is_patch {
            event_type = "patch".to_string();
-
            let patch_id = event.patch_id().ok_or(BrokerError::Trigger)?;
+
            let patch_id = event.patch_id().ok_or(MessageError::Trigger)?;
            let patch = patch::Patches::open(&repository)?
                .get(&patch_id.into())?
-
                .ok_or(BrokerError::Trigger)?;
+
                .ok_or(MessageError::Trigger)?;
            push_info = None;

            let revs: Vec<Revision> = patch
                .revisions()
                .map(|(rid, r)| {
-
                    Ok::<Revision, BrokerError>(Revision {
+
                    Ok::<Revision, MessageError>(Revision {
                        id: rid.into(),
                        author: did_to_author(profile, r.author().id())?,
                        description: r.description().to_string(),
@@ -141,11 +140,11 @@ impl Request {
                        timestamp: r.timestamp().as_secs(),
                    })
                })
-
                .collect::<Result<Vec<Revision>, BrokerError>>()?;
+
                .collect::<Result<Vec<Revision>, MessageError>>()?;
            let patch_author_pk = radicle::crypto::PublicKey::from(author.id);
            let patch_latest_revision = patch
                .latest_by(&patch_author_pk)
-
                .ok_or(BrokerError::Trigger)?;
+
                .ok_or(MessageError::Trigger)?;
            let patch_head = patch_latest_revision.1.head();
            let patch_base = patch_latest_revision.1.base();
            let patch_commits: Vec<Oid> = repo
@@ -251,13 +250,13 @@ impl Request {
    }
}

-
fn did_to_author(profile: &Profile, did: &Did) -> Result<Author, BrokerError> {
+
fn did_to_author(profile: &Profile, did: &Did) -> Result<Author, MessageError> {
    let alias = profile.aliases().alias(did);
    Ok(Author { id: *did, alias })
}

-
fn extract_author(profile: &Profile, event: &BrokerEvent) -> Result<Author, BrokerError> {
-
    let nid = event.nid().ok_or(BrokerError::Trigger)?;
+
fn extract_author(profile: &Profile, event: &BrokerEvent) -> Result<Author, MessageError> {
+
    let nid = event.nid().ok_or(MessageError::Trigger)?;
    did_to_author(profile, &Did::from(nid))
}

@@ -522,6 +521,26 @@ pub enum MessageError {
    /// Error from Radicle.
    #[error(transparent)]
    RadicleProfile(#[from] radicle::profile::Error),
+

+
    /// Error retrieving context to generate trigger from BrokerEvent
+
    #[error("could not generate trigger from event")]
+
    Trigger,
+

+
    /// Error from Radicle storage.
+
    #[error(transparent)]
+
    StorageError(#[from] radicle::storage::Error),
+

+
    /// Error from Radicle repository.
+
    #[error(transparent)]
+
    RepositoryError(#[from] radicle::storage::RepositoryError),
+

+
    /// Error from Radicle COB.
+
    #[error(transparent)]
+
    CobStoreError(#[from] radicle::cob::store::Error),
+

+
    /// Error from `radicle-surf` crate.
+
    #[error(transparent)]
+
    RadicleSurfError(#[from] radicle_surf::Error),
}

#[cfg(test)]