Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: handle run id not being set without unwrap
Lars Wirzenius committed 1 year ago
commit bbaa1c27c60610310349106ed211dce72e7ba059
parent 5fe771bd57c7df0f0c0bedc3de64a8668837189e
1 file changed +8 -2
modified src/db.rs
@@ -389,8 +389,7 @@ impl Db {

    /// Add a new CI run to the database, returning its id.
    pub fn push_run(&self, run: Run) -> Result<RunId, DbError> {
-
        assert!(run.adapter_run_id().is_some());
-
        let id = run.adapter_run_id().unwrap().clone();
+
        let id = run.adapter_run_id().ok_or(DbError::without_id())?.clone();

        let json = serde_json::to_string(&run).expect("serialize BrokerEvent to JSON");

@@ -577,6 +576,9 @@ pub enum DbError {
    #[error("failed to retrieve a CI run from database")]
    GetRun(String, #[source] sqlite::Error),

+
    #[error("programming error: pushed run does not have its run ID set")]
+
    WithoutId,
+

    #[error("failed to insert a CI run into database")]
    PushRun(String, #[source] sqlite::Error),

@@ -661,6 +663,10 @@ impl DbError {
        Self::GetRun(sql.into(), e)
    }

+
    fn without_id() -> Self {
+
        Self::WithoutId
+
    }
+

    fn push_run(sql: &str, e: sqlite::Error) -> Self {
        Self::PushRun(sql.into(), e)
    }