Skip to content

Consider a explicit Operation to Error conversion #3505

@coryan

Description

@coryan

The GCE status codes (at least for LROs) are very different from standard status codes:

https://cloud.google.com/compute/docs/reference/rest/v1/errors

Instead of automatically converting Operation to Result<Operation> maybe we should expose an explicit function, something like:

impl Operation {
  pub fn to_result(self) -> std::result::Result<Operation, OperationError> {
        if self.error.is_none() {
            return Ok(self)  
        }
        // Map the `error` and `error.errors` to an specific error type, preserving all the data.
  }
}

So an LRO becomes:

  let operation = client.insert().set_project(..).set_body(...).poller().until_done().await?;
  // here one can use operation.error.is_some() and get the error details manually, or maybe:
  let operation = operation.to_result()?; // automatically return when using `anyhow::Result` or a similar return type. 

Metadata

Metadata

Assignees

Labels

api: computeIssues related to the Compute Engine API.priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions