From de2b44169cc272479e5f2ce1afb662e0e0dbe7f5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Feb 2024 14:52:35 +0100 Subject: [PATCH 1/2] Don't crash if the client sends an invalid store path name --- magic-nix-cache/src/api.rs | 8 ++++---- magic-nix-cache/src/main.rs | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/magic-nix-cache/src/api.rs b/magic-nix-cache/src/api.rs index e0a2b72..eb9b3dc 100644 --- a/magic-nix-cache/src/api.rs +++ b/magic-nix-cache/src/api.rs @@ -9,7 +9,7 @@ use axum_macros::debug_handler; use serde::{Deserialize, Serialize}; use super::State; -use crate::error::Result; +use crate::error::{Error, Result}; use crate::util::{get_store_paths, upload_paths}; #[derive(Debug, Clone, Serialize)] @@ -112,11 +112,11 @@ async fn enqueue_paths( ) -> Result> { tracing::info!("Enqueueing {:?}", req.store_paths); - let store_paths: Vec<_> = req + let store_paths = req .store_paths .iter() - .map(|path| state.store.follow_store_path(path).unwrap()) - .collect(); + .map(|path| state.store.follow_store_path(path).map_err(Error::Attic)) + .collect::>>()?; if let Some(flakehub_state) = &*state.flakehub_state.read().await { crate::flakehub::enqueue_paths(flakehub_state, store_paths).await?; diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index c9bc62a..5c5befe 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -345,8 +345,9 @@ async fn post_build_hook(out_paths: &str) { match response { Ok(response) if !response.status().is_success() => { err_message = Some(format!( - "magic-nix-cache server failed to enqueue the push request: {}", - response.status() + "magic-nix-cache server failed to enqueue the push request: {}\n{}", + response.status(), + response.text().await.unwrap_or_else(|_| "".to_owned()), )); } Ok(response) => { From 7965e647fe533e4eb4fa85c0ae7bdd9f9814a89a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Feb 2024 15:05:59 +0100 Subject: [PATCH 2/2] Fix support for multiple output derivations OUT_PATHS is split by spaces, not newlines. --- magic-nix-cache/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 5c5befe..c31bc8e 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -330,7 +330,10 @@ async fn post_build_hook(out_paths: &str) { let args = Args::parse(); - let store_paths: Vec<_> = out_paths.lines().map(str::to_owned).collect(); + let store_paths: Vec<_> = out_paths + .split_whitespace() + .map(|s| s.trim().to_owned()) + .collect(); let request = api::EnqueuePathsRequest { store_paths };