Skip to content

Commit

Permalink
feat: offer to save evidence on failure
Browse files Browse the repository at this point in the history
resolves #105
  • Loading branch information
lilopkins committed Nov 6, 2023
1 parent 2d1baa1 commit 3d89da7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions testangel/locales/en/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ flow-save-open-error-missing-action = The action for step { $step } (with intern
flow-execution-running = Flow running...
flow-execution-failed = Flow failed.
flow-execution-failed-message = Flow failed at step { $step }: { $reason }
flow-execution-save-evidence-anyway = Save Evidence Anyway
flow-step-label = Step { $step }: { $name }
Expand Down
1 change: 1 addition & 0 deletions testangel/locales/sv/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ flow-save-open-error-missing-action = Åtgärden för steg { $step } (med intern
flow-execution-running = Flöde körs...
flow-execution-failed = Flödet misslyckades.
flow-execution-failed-message = Flödet misslyckades på steg { $step }: { $reason }
flow-execution-save-evidence-anyway = Spara bevis ändå
flow-step-label = Steg { $step }: { $name }
Expand Down
48 changes: 30 additions & 18 deletions testangel/src/ui/flows/execution_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum ExecutionDialogCommandOutput {
Complete(Vec<Evidence>),

/// Execution failed at the given step and for the given reason
Failed(usize, FlowError),
Failed(usize, FlowError, Vec<Evidence>),
}

#[derive(Debug)]
Expand All @@ -32,6 +32,7 @@ pub struct ExecutionDialogInit {
pub enum ExecutionDialogInput {
Close,
FailedToGenerateReport(ReportGenerationError),
SaveEvidence(Vec<Evidence>),
}

#[derive(Debug)]
Expand Down Expand Up @@ -105,6 +106,9 @@ impl Component for ExecutionDialog {
}

for (step, action_config) in flow.actions.iter().enumerate() {
log::debug!("Output state: {outputs:?}");
log::debug!("Evidence state: {evidence:?}");
log::debug!("Executing: {action_config:?}");
match action_config.execute(
action_map.clone(),
engine_list.clone(),
Expand All @@ -115,7 +119,7 @@ impl Component for ExecutionDialog {
evidence = [evidence, ev].concat();
}
Err(e) => {
return ExecutionDialogCommandOutput::Failed(step + 1, e);
return ExecutionDialogCommandOutput::Failed(step + 1, e, evidence);
}
}
}
Expand Down Expand Up @@ -153,19 +157,7 @@ impl Component for ExecutionDialog {
});
dialog.set_visible(true);
}
}
}

fn update_cmd(
&mut self,
message: Self::CommandOutput,
sender: relm4::ComponentSender<Self>,
root: &Self::Root,
) {
match message {
ExecutionDialogCommandOutput::Complete(evidence) => {
log::info!("Execution complete.");

ExecutionDialogInput::SaveEvidence(evidence) => {
// Present save dialog
let dialog = gtk::FileDialog::builder()
.modal(true)
Expand Down Expand Up @@ -199,9 +191,23 @@ impl Component for ExecutionDialog {
},
);
}
}
}

ExecutionDialogCommandOutput::Failed(step, reason) => {
log::warn!("Execution failed");
fn update_cmd(
&mut self,
message: Self::CommandOutput,
sender: relm4::ComponentSender<Self>,
root: &Self::Root,
) {
match message {
ExecutionDialogCommandOutput::Complete(evidence) => {
log::info!("Execution complete.");
sender.input(ExecutionDialogInput::SaveEvidence(evidence));
}

ExecutionDialogCommandOutput::Failed(step, reason, evidence) => {
log::warn!("Execution failed. Evidence: {evidence:?}");
let dialog = self.create_message_dialog(
lang::lookup("flow-execution-failed"),
lang::lookup_with_args("flow-execution-failed-message", {
Expand All @@ -212,10 +218,16 @@ impl Component for ExecutionDialog {
}),
);
dialog.set_transient_for(Some(root));
if !evidence.is_empty() {
dialog.add_response("save", &lang::lookup("flow-execution-save-evidence-anyway"));
}
dialog.add_response("ok", &lang::lookup("ok"));
dialog.set_default_response(Some("ok"));
let sender_c = sender.clone();
dialog.connect_response(None, move |dlg, _response| {
dialog.connect_response(None, move |dlg, response| {
if response == "save" {
sender_c.input(ExecutionDialogInput::SaveEvidence(evidence.clone()));
}
sender_c.input(ExecutionDialogInput::Close);
dlg.close();
});
Expand Down

0 comments on commit 3d89da7

Please sign in to comment.