Skip to content

Commit 33934e9

Browse files
authored
cleanup(compute/v1): prefer to_result() for errors (#3601)
1 parent e5596f4 commit 33934e9

File tree

7 files changed

+26
-449
lines changed

7 files changed

+26
-449
lines changed

guide/samples/src/compute.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ pub async fn cleanup_stale_instances(client: &Instances, project_id: &str) -> an
6060
}
6161
if let (Some(name), Some(zone)) = (instance.name, instance.zone) {
6262
println!("Deleting VM {name} in zone {zone}");
63-
let _ = client
63+
let result = client
6464
.delete()
6565
.set_project(project_id)
6666
.set_zone(zone)
6767
.set_instance(name)
6868
.poller()
6969
.until_done()
70-
.await?;
70+
.await;
71+
match result {
72+
Err(e) => println!("operation did not complete, error={e:?}"),
73+
Ok(op) => println!("operation completed with {:?}", op.to_result()),
74+
};
7175
}
7276
}
7377
}

guide/samples/src/compute/compute_instances_create.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub async fn sample(client: &Instances, project_id: &str, name: &str) -> anyhow:
4343
.set_body(instance)
4444
.poller()
4545
.until_done()
46-
.await?;
46+
.await?
47+
.to_result()?;
4748
println!("Instance successfully created: {operation:?}");
4849

4950
Ok(())

guide/samples/src/compute/compute_instances_delete.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ pub async fn sample(client: &Instances, project_id: &str, name: &str) -> anyhow:
2626
.set_instance(name)
2727
.poller()
2828
.until_done()
29-
.await?;
29+
.await?
30+
.to_result()?;
3031
println!("Instance successfully deleted: {operation:?}");
3132

3233
Ok(())

guide/samples/src/compute/compute_instances_operation_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn sample(client: &Instances, project_id: &str, name: &str) -> anyhow:
4848

4949
println!("Instance creation finished: {operation:?}");
5050
// Check if there was an error.
51-
if let Some(error) = &operation.error {
51+
if let Err(error) = operation.to_result() {
5252
println!("Instance creation failed: {error:?}");
5353
return Err(anyhow::Error::msg(format!(
5454
"instance creation failed with: {error:?}"

guide/samples/src/compute/compute_usage_report_set.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pub async fn sample(client: &Projects, project_id: &str, bucket_name: &str) -> a
3939
)
4040
.poller()
4141
.until_done()
42-
.await?;
42+
.await?
43+
.to_result()?;
4344
println!("Setting the usage export bucket completed successfully: {operation:?}");
4445

4546
Ok(())

0 commit comments

Comments
 (0)