From 1d978569227a448127f266de6cefbc900b0b3dac Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Wed, 9 Feb 2022 13:26:19 -0700 Subject: [PATCH] better devtools --- backend/src/config/mod.rs | 21 +++++++++++++++++++++ backend/src/developer/mod.rs | 5 +++++ backend/src/install/mod.rs | 30 +++++++++++++++++++++++++++--- backend/src/lib.rs | 2 +- backend/src/s9pk/mod.rs | 2 +- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/backend/src/config/mod.rs b/backend/src/config/mod.rs index fe13386a4..d0a9f89e9 100644 --- a/backend/src/config/mod.rs +++ b/backend/src/config/mod.rs @@ -1,4 +1,5 @@ use std::collections::{BTreeMap, BTreeSet}; +use std::path::PathBuf; use std::time::Duration; use color_eyre::eyre::eyre; @@ -137,6 +138,26 @@ pub enum MatchError { ListUniquenessViolation, } +#[command(rename = "config-spec", cli_only, blocking, display(display_none))] +pub fn verify_spec(#[arg] path: PathBuf) -> Result<(), Error> { + let mut file = std::fs::File::open(&path)?; + let format = match path.extension().and_then(|s| s.to_str()) { + Some("yaml") | Some("yml") => IoFormat::Yaml, + Some("json") => IoFormat::Json, + Some("toml") => IoFormat::Toml, + Some("cbor") => IoFormat::Cbor, + _ => { + return Err(Error::new( + eyre!("Unknown file format. Expected one of yaml, json, toml, cbor."), + crate::ErrorKind::Deserialization, + )); + } + }; + let _: ConfigSpec = format.from_reader(&mut file)?; + + Ok(()) +} + #[command(subcommands(get, set))] pub fn config(#[arg] id: PackageId) -> Result { Ok(id) diff --git a/backend/src/developer/mod.rs b/backend/src/developer/mod.rs index 9d2106e5c..bf2ded3c3 100644 --- a/backend/src/developer/mod.rs +++ b/backend/src/developer/mod.rs @@ -28,3 +28,8 @@ pub fn init(#[context] ctx: SdkContext) -> Result<(), Error> { } Ok(()) } + +#[command(subcommands(crate::s9pk::verify, crate::config::verify_spec))] +pub fn verify() -> Result<(), Error> { + Ok(()) +} diff --git a/backend/src/install/mod.rs b/backend/src/install/mod.rs index b2d67f7d9..35314e224 100644 --- a/backend/src/install/mod.rs +++ b/backend/src/install/mod.rs @@ -359,9 +359,8 @@ pub async fn sideload( } pde.save(&mut tx).await?; tx.commit(None).await?; - drop(hdl); - download_install_s9pk( + if let Err(e) = download_install_s9pk( &new_ctx, &manifest, None, @@ -377,7 +376,32 @@ pub async fn sideload( ) })), ) - .await?; + .await + { + let err_str = format!( + "Install of {}@{} Failed: {}", + manifest.id, manifest.version, e + ); + tracing::error!("{}", err_str); + tracing::debug!("{:?}", e); + if let Err(e) = new_ctx + .notification_manager + .notify( + &mut hdl, + Some(manifest.id), + NotificationLevel::Error, + String::from("Install Failed"), + err_str, + (), + None, + ) + .await + { + tracing::error!("Failed to issue Notification: {}", e); + tracing::debug!("{:?}", e); + } + } + Response::builder() .status(StatusCode::OK) .body(Body::empty()) diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 87f695c5d..dfab0e809 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -110,7 +110,7 @@ pub fn package() -> Result<(), RpcError> { #[command(subcommands( version::git_info, s9pk::pack, - s9pk::verify, + developer::verify, developer::init, inspect::inspect ))] diff --git a/backend/src/s9pk/mod.rs b/backend/src/s9pk/mod.rs index 3ba3a9cc0..8d0c8530c 100644 --- a/backend/src/s9pk/mod.rs +++ b/backend/src/s9pk/mod.rs @@ -107,7 +107,7 @@ pub fn pack(#[context] ctx: SdkContext, #[arg] path: Option) -> Result< Ok(()) } -#[command(cli_only, display(display_none))] +#[command(rename = "s9pk", cli_only, display(display_none))] pub async fn verify(#[arg] path: PathBuf) -> Result<(), Error> { let mut s9pk = S9pkReader::open(path, true).await?; s9pk.validate().await?;