Skip to content

Commit e162cf1

Browse files
Copilotjosecelano
andcommitted
fix: [#105] improve error mapping for context creation failures
Co-authored-by: josecelano <[email protected]>
1 parent b61ffea commit e162cf1

File tree

1 file changed

+16
-15
lines changed
  • src/infrastructure/external_tools/ansible/template/renderer

1 file changed

+16
-15
lines changed

src/infrastructure/external_tools/ansible/template/renderer/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ pub enum ConfigurationTemplateError {
138138
#[source]
139139
source: variables::VariablesTemplateError,
140140
},
141+
142+
/// Failed to create context from inventory data
143+
#[error("Failed to create {context_type} context: {message}")]
144+
ContextCreationFailed {
145+
context_type: String,
146+
message: String,
147+
},
141148
}
142149

143150
/// Renders `Ansible` configuration templates to a build directory
@@ -439,21 +446,17 @@ impl AnsibleTemplateRenderer {
439446

440447
// Extract SSH port from inventory context
441448
let ssh_port = AnsiblePort::new(inventory_context.ansible_port()).map_err(|e| {
442-
ConfigurationTemplateError::TemplatePathFailed {
443-
file_name: "configure-firewall.yml.tera".to_string(),
444-
source: TemplateManagerError::TemplateNotFound {
445-
relative_path: format!("Invalid SSH port: {e}"),
446-
},
449+
ConfigurationTemplateError::ContextCreationFailed {
450+
context_type: "FirewallPlaybook".to_string(),
451+
message: format!("Invalid SSH port: {e}"),
447452
}
448453
})?;
449454

450455
// Create firewall context
451456
FirewallPlaybookContext::new(ssh_port).map_err(|e| {
452-
ConfigurationTemplateError::TemplatePathFailed {
453-
file_name: "configure-firewall.yml.tera".to_string(),
454-
source: TemplateManagerError::TemplateNotFound {
455-
relative_path: format!("Failed to create firewall context: {e}"),
456-
},
457+
ConfigurationTemplateError::ContextCreationFailed {
458+
context_type: "FirewallPlaybook".to_string(),
459+
message: format!("Failed to create firewall context: {e}"),
457460
}
458461
})
459462
}
@@ -484,11 +487,9 @@ impl AnsibleTemplateRenderer {
484487

485488
// Extract SSH port from inventory context and create variables context
486489
AnsibleVariablesContext::new(inventory_context.ansible_port()).map_err(|e| {
487-
ConfigurationTemplateError::TemplatePathFailed {
488-
file_name: "variables.yml.tera".to_string(),
489-
source: TemplateManagerError::TemplateNotFound {
490-
relative_path: format!("Failed to create variables context: {e}"),
491-
},
490+
ConfigurationTemplateError::ContextCreationFailed {
491+
context_type: "AnsibleVariables".to_string(),
492+
message: format!("Failed to create variables context: {e}"),
492493
}
493494
})
494495
}

0 commit comments

Comments
 (0)