Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions crates/alien-cli/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,38 @@ fn resolve_deploy_args(args: &DeployArgs) -> Result<ResolvedDeployArgs> {
}

fn read_deploy_config(path: &Path) -> Result<DeployConfigFile> {
let resolved_path = resolved_config_path(path);
let contents = std::fs::read_to_string(path).into_alien_error().context(
ErrorData::FileOperationFailed {
operation: "read".to_string(),
file_path: path.display().to_string(),
reason: "Failed to read deploy config".to_string(),
file_path: resolved_path.display().to_string(),
reason: format!(
"Failed to read deploy config '{}' (relative paths are resolved from the current working directory)",
path.display()
),
},
)?;
toml::from_str(&contents)
.into_alien_error()
.context(ErrorData::ConfigurationError {
message: format!("Failed to parse deploy config {}", path.display()),
message: format!(
"Failed to parse deploy config '{}' (resolved as '{}')",
path.display(),
resolved_path.display()
),
})
}

fn resolved_config_path(path: &Path) -> PathBuf {
if path.is_absolute() {
path.to_path_buf()
} else {
std::env::current_dir()
.map(|cwd| cwd.join(path))
.unwrap_or_else(|_| path.to_path_buf())
}
}

fn resolve_network_settings(
args: &DeployArgs,
config: Option<&DeployConfigFile>,
Expand Down Expand Up @@ -1772,6 +1790,20 @@ fn target_release_from_json(
mod tests {
use super::*;

#[test]
fn missing_relative_config_error_shows_resolved_path_rule() {
let path = Path::new("definitely-missing/deployment.toml");
let error = read_deploy_config(path).expect_err("missing config should fail");
assert!(error.message.contains("current working directory"));
assert!(error.message.contains("definitely-missing/deployment.toml"));
assert!(error.message.contains(
&std::env::current_dir()
.expect("current directory")
.display()
.to_string()
));
}

#[test]
fn target_release_requires_a_stack_for_the_deployment_platform() {
let error = target_release_from_json(
Expand Down
4 changes: 4 additions & 0 deletions crates/alien-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub mod dev_helpers;
pub mod init;
pub mod logs;
pub mod onboard;
#[cfg(feature = "platform")]
pub mod packages;
pub mod release;
pub mod releases;
pub mod render;
Expand Down Expand Up @@ -47,6 +49,8 @@ pub use dev_helpers::{
pub use init::{init_task, InitArgs};
pub use logs::{logs_task, LogsArgs};
pub use onboard::{onboard_task, OnboardArgs};
#[cfg(feature = "platform")]
pub use packages::{packages_task, PackagesArgs};
pub use release::{release_command, ReleaseArgs};
pub use releases::{releases_task, ReleasesArgs};
pub use render::{render_task, RenderArgs};
Expand Down
Loading
Loading