Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
chore: drop anyhow in favor of just thiserror
Lars Wirzenius committed 2 years ago
commit af03df85177e52046c75dd4f078f955817e3efb8
parent f31ff2718fd5b4c500bd94580fcbd1fe00fb3e60
5 files changed +42 -13
modified Cargo.lock
@@ -64,12 +64,6 @@ dependencies = [
]

[[package]]
-
name = "anyhow"
-
version = "1.0.75"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
-

-
[[package]]
name = "ascii"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -983,7 +977,6 @@ dependencies = [
name = "radicle-ci-broker"
version = "0.1.0"
dependencies = [
-
 "anyhow",
 "log",
 "pretty_env_logger",
 "radicle",
modified Cargo.toml
@@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
-
anyhow = "1.0.75"
log = "0.4.20"
pretty_env_logger = "0.5.0"
radicle-git-ext = "0.7.0"
modified src/bin/ci-broker.rs
@@ -1,4 +1,5 @@
use std::{
+
    error::Error,
    io::BufReader,
    path::Path,
    process::{Command, Stdio},
@@ -10,11 +11,22 @@ use radicle::prelude::{Id, Profile};
use radicle_ci_broker::{
    event::NodeEventSource,
    filter::{BrokerEvent, EventFilter},
-
    msg::{Request, Response, RunResult},
+
    msg::{BrokerError, Request, Response, RunResult},
};
use radicle_git_ext::Oid;

-
fn main() -> anyhow::Result<()> {
+
fn main() {
+
    if let Err(e) = fallible_main() {
+
        eprintln!("ERROR: {}", e);
+
        let mut e = e.source();
+
        while let Some(source) = e {
+
            eprintln!("caused by: {}", source);
+
            e = source.source();
+
        }
+
    }
+
}
+

+
fn fallible_main() -> Result<(), BrokerError> {
    pretty_env_logger::init();
    info!("Radicle CI broker starts");

@@ -57,7 +69,7 @@ fn main() -> anyhow::Result<()> {
    }
}

-
fn run(bin: &str, repo: Id, commit: Oid) -> anyhow::Result<Option<RunResult>> {
+
fn run(bin: &str, repo: Id, commit: Oid) -> Result<Option<RunResult>, BrokerError> {
    info!("Trigger on {}, {}", repo, commit);

    debug!("Spawning child process");
modified src/bin/node-events.rs
@@ -1,9 +1,22 @@
+
use std::error::Error;
+

use log::info;

use radicle::Profile;
-
use radicle_ci_broker::{event::NodeEventSource, filter::EventFilter};
+
use radicle_ci_broker::{event::NodeEventSource, filter::EventFilter, msg::BrokerError};
+

+
fn main() {
+
    if let Err(e) = fallible_main() {
+
        eprintln!("ERROR: {}", e);
+
        let mut e = e.source();
+
        while let Some(source) = e {
+
            eprintln!("caused by: {}", source);
+
            e = source.source();
+
        }
+
    }
+
}

-
fn main() -> anyhow::Result<()> {
+
fn fallible_main() -> Result<(), BrokerError> {
    pretty_env_logger::init();
    info!("ci-broker-prototype starts");

modified src/msg.rs
@@ -204,4 +204,16 @@ pub enum BrokerError {
    /// Failed to parse JSON as a response or a response.
    #[error("failed to read a JSON request from a file handle")]
    DeserializeResponse(#[source] serde_json::Error),
+

+
    /// Error from an node event subscriber.
+
    #[error(transparent)]
+
    NodeEvent(#[from] crate::event::NodeEventError),
+

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

+
    /// Error from spawning a sub-process.
+
    #[error(transparent)]
+
    Spawn(#[from] std::io::Error),
}