Page MenuHomeDevCentral

D3010.diff
No OneTemporary

D3010.diff

diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "alkane"
-version = "0.1.0"
+version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/actions.rs b/src/actions.rs
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -26,45 +26,52 @@
// Actions available both for CLI and HTTP
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-pub fn initialize(
+fn run_deployment_action(
site_name: &str,
context: Option<String>,
config: &AlkaneConfig,
+ action: &str,
) -> Result<RecipeStatus, DeployError> {
let db = Database::from_config(config).ok_or_else(|| {
- let error = AlkaneDeployError::new("Can't initialize database");
+ let error = AlkaneDeployError::new("Can't initialize database", site_name, action);
DeployError::Alkane(error)
})?;
let recipes = RecipesStore::from_config(config).ok_or_else(|| {
- let error = AlkaneDeployError::new("Can't initialize recipes store");
+ let error = AlkaneDeployError::new("Can't initialize recipes store", site_name, action);
DeployError::Alkane(error)
})?;
let site = config
.get_site(site_name, context)
- .expect("Can't get site path.");
- let status = recipes.run_recipe(&site, "init");
- db.set_initialized(&site.name);
+ .ok_or_else(|| {
+ let error = AlkaneDeployError::new("Can't resolve site path", site_name, action);
+ DeployError::Alkane(error)
+ })?;
+
+ let status = recipes.run_recipe(&site, action);
+
+ if action == "init" {
+ db.set_initialized(&site.name);
+ }
Ok(status)
}
-pub fn update(
+pub fn initialize(
site_name: &str,
context: Option<String>,
config: &AlkaneConfig,
) -> Result<RecipeStatus, DeployError> {
- let recipes = RecipesStore::from_config(config).ok_or_else(|| {
- let error = AlkaneDeployError::new("Can't initialize recipes store");
- DeployError::Alkane(error)
- })?;
+ run_deployment_action(site_name, context, config, "init")
+}
- let site = config
- .get_site(site_name, context)
- .expect("Can't get site path.");
- let status = recipes.run_recipe(&site, "update");
- Ok(status)
+pub fn update(
+ site_name: &str,
+ context: Option<String>,
+ config: &AlkaneConfig,
+) -> Result<RecipeStatus, DeployError> {
+ run_deployment_action(site_name, context, config, "update")
}
pub fn deploy(
@@ -73,9 +80,9 @@
config: &AlkaneConfig,
) -> Result<RecipeStatus, DeployError> {
if is_present(site_name, config) {
- update(site_name, context, config)
+ run_deployment_action(site_name, context, config, "update")
} else {
- initialize(site_name, context, config)
+ run_deployment_action(site_name, context, config, "init")
}
}
diff --git a/src/deploy.rs b/src/deploy.rs
--- a/src/deploy.rs
+++ b/src/deploy.rs
@@ -16,23 +16,31 @@
#[derive(Debug)]
pub struct AlkaneDeployError {
pub message: String,
+
+ /// The name of the site to deploy
+ pub site_name: String,
+
+ /// The deployment action, "init" or "update"
+ pub action: String,
}
impl Display for AlkaneDeployError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- write!(f, "Alkane deploy error: {}", self.message)
+ write!(f, "Can't run deployment action '{}' for site '{}': {}", self.action, self.site_name, self.message)
}
}
impl Error for AlkaneDeployError {}
impl AlkaneDeployError {
- pub fn new<S>(message: S) -> Self
+ pub fn new<S>(message: S, site_name: S, action: S) -> Self
where
S: AsRef<str>,
{
Self {
message: message.as_ref().to_string(),
+ site_name: site_name.as_ref().to_string(),
+ action: action.as_ref().to_string(),
}
}
}
@@ -45,3 +53,11 @@
pub enum DeployError {
Alkane(AlkaneDeployError),
}
+
+impl Display for DeployError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ DeployError::Alkane(error) => error.fmt(f),
+ }
+ }
+}
diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -89,7 +89,7 @@
Ok(status) => exit(status.to_status_code()),
Err(error) => {
- eprintln!("Can't deploy: {:?}", error);
+ eprintln!("{}", error);
exit(16);
}
}
diff --git a/src/server/requests.rs b/src/server/requests.rs
--- a/src/server/requests.rs
+++ b/src/server/requests.rs
@@ -47,7 +47,7 @@
match actions::initialize(&site_name, context, &config) {
Ok(status) => status.into_json_response(),
Err(error) => {
- warn!("Deployment error: {:?}", error);
+ warn!("{}", error);
RecipeStatus::Error.into_json_response()
}
@@ -68,7 +68,7 @@
match actions::update(&site_name, context, &config) {
Ok(status) => status.into_json_response(),
Err(error) => {
- warn!("Deployment error: {:?}", error);
+ warn!("{}", error);
RecipeStatus::Error.into_json_response()
}
@@ -89,7 +89,7 @@
match actions::deploy(&site_name, context, &config) {
Ok(status) => status.into_json_response(),
Err(error) => {
- warn!("Deployment error: {:?}", error);
+ warn!("{}", error);
RecipeStatus::Error.into_json_response()
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 06:21 (8 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2257694
Default Alt Text
D3010.diff (5 KB)

Event Timeline