Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat(src/broker.rs): handle time formatting errors without panic
Lars Wirzenius committed 1 year ago
commit 573bc76a20b3210605596a4cf744dda4aa0d3b98
parent 07ed0639e7478a1ed3f3cd7f43397441804dd0cc
1 file changed +7 -3
modified src/broker.rs
@@ -98,7 +98,7 @@ impl Broker {
                        panic!("neither push not patch event");
                    };

-
                    let mut run = Run::new(*rid, &common.repository.name, whence, now());
+
                    let mut run = Run::new(*rid, &common.repository.name, whence, now()?);

                    // We run the adapter, but if that fails, we just
                    // log the error. The `Run` value records the
@@ -135,15 +135,19 @@ impl Broker {
    }
}

-
fn now() -> String {
+
fn now() -> Result<String, time::error::Format> {
    let fmt = format_description!("[year]-[month]-[day] [hour]:[minute]:[second]Z");
-
    OffsetDateTime::now_utc().format(fmt).expect("format time")
+
    OffsetDateTime::now_utc().format(fmt)
}

/// All possible errors from this module.
#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
pub enum BrokerError {
+
    /// Error formatting a time as a string.
+
    #[error(transparent)]
+
    Timeformat(#[from] time::error::Format),
+

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