Skip to content

Commit

Permalink
improve error handling via step
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli committed Dec 20, 2023
1 parent 9e842e7 commit a659ec2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ use vergen::EmitBuilder;
fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder().all_git().emit()?;
Ok(())
}
}
68 changes: 50 additions & 18 deletions scenarios/init_account.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
},
{
"id": 4,
"config": {
"type": "check-step",
"parameters": {
"outcome": {
"type": "value",
"value": "success"
},
"id": {
"type": "value",
"value": "3"
}
}
}
},
{
"id": 5,
"config": {
"type": "check-balance",
"parameters": {
Expand All @@ -69,7 +85,7 @@
}
},
{
"id": 5,
"id": 6,
"config": {
"type": "tx-transparent-transfer",
"parameters": {
Expand All @@ -94,7 +110,23 @@
}
},
{
"id": 6,
"id": 7,
"config": {
"type": "check-step",
"parameters": {
"outcome": {
"type": "value",
"value": "success"
},
"id": {
"type": "value",
"value": "6"
}
}
}
},
{
"id": 8,
"config": {
"type": "check-balance",
"parameters": {
Expand All @@ -115,7 +147,7 @@
}
},
{
"id": 7,
"id": 9,
"config": {
"type": "tx-transparent-transfer",
"parameters": {
Expand All @@ -140,13 +172,13 @@
}
},
{
"id": 8,
"id": 10,
"config": {
"type": "check-balance",
"parameters": {
"amount": {
"type": "ref",
"value": 7,
"value": 9,
"field": "amount"
},
"address": {
Expand All @@ -162,7 +194,7 @@
}
},
{
"id": 9,
"id": 1,
"config": {
"type": "reveal-pk",
"parameters": {
Expand All @@ -175,7 +207,7 @@
}
},
{
"id": 10,
"id": 12,
"config": {
"type": "tx-init-account",
"parameters": {
Expand Down Expand Up @@ -203,7 +235,7 @@
}
},
{
"id": 11,
"id": 13,
"config": {
"type": "tx-transparent-transfer",
"parameters": {
Expand All @@ -213,7 +245,7 @@
},
"target": {
"type": "ref",
"value": 10,
"value": 12,
"field": "alias"
},
"amount": {
Expand All @@ -228,18 +260,18 @@
}
},
{
"id": 12,
"id": 14,
"config": {
"type": "check-balance",
"parameters": {
"amount": {
"type": "ref",
"value": 11,
"value": 13,
"field": "amount"
},
"address": {
"type": "ref",
"value": 10,
"value": 12,
"field": "alias"
},
"token": {
Expand All @@ -250,7 +282,7 @@
}
},
{
"id": 13,
"id": 15,
"config": {
"type": "check-step",
"parameters": {
Expand All @@ -260,26 +292,26 @@
},
"id": {
"type": "value",
"value": "11"
"value": "13"
}
}
}
},
{
"id": 14,
"id": 16,
"config": {
"type": "query-account",
"parameters": {
"address": {
"type": "ref",
"value": 10,
"value": 12,
"field": "alias"
}
}
}
},
{
"id": 15,
"id": 17,
"config": {
"type": "check-step",
"parameters": {
Expand All @@ -289,7 +321,7 @@
},
"id": {
"type": "value",
"value": "14"
"value": "16"
}
}
}
Expand Down
53 changes: 29 additions & 24 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,18 @@ impl Runner {
let sdk = Sdk::new(config, &base_dir, http_client, wallet, shielded_ctx, io).await;

for step in &scenario.steps {
let successful_prev_step = if step.id.eq(&0) {
true
println!("Running step {}...", step.config);
let result = step.run(&self.storage, &sdk).await;
if result.is_succesful() {
println!("Step {} executed succesfully.", step.config);
self.storage.save_step_result(step.id, result)
} else if result.is_fail() {
println!("Step {} errored bepbop.", step.config);
self.storage.save_step_result(step.id, result)
} else {
self.storage.is_step_successful(&(step.id - 1))
};

if successful_prev_step {
println!("Running step {}...", step.config);
let result = step.run(&self.storage, &sdk).await;
if result.is_succesful() {
println!("Step {} executed succesfully.", step.config);
self.storage.save_step_result(step.id, result)
} else if result.is_fail() {
println!("Step {} errored bepbop.", step.config);
self.storage.save_step_result(step.id, result)
} else {
println!("Step check {} errored riprip.", step.config);
self.storage.save_step_result(step.id, result);
break;
}
println!("Step check {} errored riprip.", step.config);
self.storage.save_step_result(step.id, result);
break;
}
}

Expand All @@ -74,14 +66,20 @@ impl Runner {
) {
let mut sha_short = sha.clone();
sha_short.truncate(8);
let scenario_name = &config.scenario.replace(".json", "").replace("scenarios/", "");
let report_name = format!("report-{}-{}-{}.md", config.chain_id, scenario_name, sha_short);
let scenario_name = &config
.scenario
.replace(".json", "")
.replace("scenarios/", "");
let report_name = format!(
"report-{}-{}-{}.md",
config.chain_id, scenario_name, sha_short
);

println!("Building report...");

let (report_path, outcome) = Report::new(config, self.storage.clone(), scenario)
.generate_report(&base_dir, &report_name);

println!("Uploading report...");

Report::upload_report(
Expand All @@ -92,8 +90,15 @@ impl Runner {
&report_path,
)
.await;
Report::update_commit_status(report_url, artifacts_url, &outcome, &sha, &report_name, &scenario_name)
.await;
Report::update_commit_status(
report_url,
artifacts_url,
&outcome,
&sha,
&report_name,
&scenario_name,
)
.await;
} else {
println!("Skipping report submission.");
}
Expand Down

0 comments on commit a659ec2

Please sign in to comment.