|
1 | 1 | //! This module provides bindings to for submitting jobs to and retrieving them from |
2 | 2 | //! Rigetti QPUs using the QCS API. |
3 | 3 |
|
4 | | -use std::{fmt, time::Duration}; |
| 4 | +use std::{convert::TryFrom, fmt, time::Duration}; |
5 | 5 |
|
6 | 6 | use cached::proc_macro::cached; |
7 | 7 | use derive_builder::Builder; |
@@ -302,16 +302,18 @@ pub async fn retrieve_results( |
302 | 302 | .ok_or_else(|| GrpcClientError::ResponseEmpty("Job Execution Results".into())) |
303 | 303 | .map_err(QpuApiError::from) |
304 | 304 | .and_then( |
305 | | - |result| match controller_job_execution_result::Status::from_i32(result.status) { |
306 | | - Some(controller_job_execution_result::Status::Success) => Ok(result), |
307 | | - status => Err(QpuApiError::JobExecutionFailed { |
308 | | - status: status |
309 | | - .map_or("UNDEFINED", |status| status.as_str_name()) |
310 | | - .to_string(), |
| 305 | + |result| match controller_job_execution_result::Status::try_from(result.status) { |
| 306 | + Ok(controller_job_execution_result::Status::Success) => Ok(result), |
| 307 | + Ok(status) => Err(QpuApiError::JobExecutionFailed { |
| 308 | + status: status.as_str_name().to_string(), |
311 | 309 | message: result |
312 | 310 | .status_message |
313 | 311 | .unwrap_or("No message provided.".to_string()), |
314 | 312 | }), |
| 313 | + Err(s) => Err(QpuApiError::InvalidJobStatus { |
| 314 | + status: result.status, |
| 315 | + message: s.to_string(), |
| 316 | + }), |
315 | 317 | }, |
316 | 318 | ) |
317 | 319 | } |
@@ -688,4 +690,15 @@ pub enum QpuApiError { |
688 | 690 | /// The message associated with the failed job. |
689 | 691 | message: String, |
690 | 692 | }, |
| 693 | + |
| 694 | + /// Error that can occur if a numeric status identifier cannot be converted |
| 695 | + /// into a known status type. |
| 696 | + #[error("The request returned an invalid status: {status}. {message}")] |
| 697 | + InvalidJobStatus { |
| 698 | + /// The numeric status identifier. |
| 699 | + status: i32, |
| 700 | + /// The message describing the failure to convert the numeric status |
| 701 | + /// identifier into a known status type. |
| 702 | + message: String, |
| 703 | + }, |
691 | 704 | } |
0 commit comments