diff --git a/Cargo.lock b/Cargo.lock index d2e8be5..0bf8036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1314,6 +1314,7 @@ dependencies = [ name = "magic-nix-cache" version = "0.1.1" dependencies = [ + "anyhow", "attic", "attic-client", "axum", diff --git a/magic-nix-cache/Cargo.toml b/magic-nix-cache/Cargo.toml index 14c30ae..3a12137 100644 --- a/magic-nix-cache/Cargo.toml +++ b/magic-nix-cache/Cargo.toml @@ -29,6 +29,7 @@ attic = { git = "ssh://git@github.com/DeterminateSystems/attic-priv", branch = " attic-client = { git = "ssh://git@github.com/DeterminateSystems/attic-priv", branch = "main" } #attic-client = { path = "../../attic-priv/client" } indicatif = "0.17" +anyhow = "1.0.71" [dependencies.tokio] version = "1.28.0" diff --git a/magic-nix-cache/src/api.rs b/magic-nix-cache/src/api.rs index ff04c87..e0a2b72 100644 --- a/magic-nix-cache/src/api.rs +++ b/magic-nix-cache/src/api.rs @@ -119,9 +119,7 @@ async fn enqueue_paths( .collect(); if let Some(flakehub_state) = &*state.flakehub_state.read().await { - crate::flakehub::enqueue_paths(flakehub_state, store_paths) - .await - .unwrap(); + crate::flakehub::enqueue_paths(flakehub_state, store_paths).await?; } Ok(Json(EnqueuePathsResponse {})) diff --git a/magic-nix-cache/src/error.rs b/magic-nix-cache/src/error.rs index 574b9d9..686cfdd 100644 --- a/magic-nix-cache/src/error.rs +++ b/magic-nix-cache/src/error.rs @@ -27,6 +27,9 @@ pub enum Error { #[error("GHA cache is disabled")] GHADisabled, + + #[error("FlakeHub cache error: {0}")] + FlakeHub(anyhow::Error), } impl IntoResponse for Error { diff --git a/magic-nix-cache/src/flakehub.rs b/magic-nix-cache/src/flakehub.rs index 958f639..104b6a1 100644 --- a/magic-nix-cache/src/flakehub.rs +++ b/magic-nix-cache/src/flakehub.rs @@ -1,4 +1,4 @@ -use crate::error::Result; +use crate::error::{Error, Result}; use attic::api::v1::cache_config::{CreateCacheRequest, KeypairConfig}; use attic::cache::CacheSliceIdentifier; use attic::nix_store::{NixStore, StorePath}; @@ -20,8 +20,6 @@ const JWT_PREFIX: &str = "flakehub1_"; const USER_AGENT: &str = "magic-nix-cache"; pub struct State { - cache: CacheSliceIdentifier, - pub substituter: String, pub push_session: PushSession, @@ -250,14 +248,16 @@ pub async fn init_cache( }); Ok(State { - cache, substituter: flakehub_cache_server.to_owned(), push_session, }) } pub async fn enqueue_paths(state: &State, store_paths: Vec) -> Result<()> { - state.push_session.queue_many(store_paths).unwrap(); + state + .push_session + .queue_many(store_paths) + .map_err(Error::FlakeHub)?; Ok(()) }