Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch services to thiserror #205

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion services/mgmt/addons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1.0"
snafu = "0.6"
thiserror = "1.0"
http = "0.2"
url = "2.2"

Expand Down
337 changes: 170 additions & 167 deletions services/mgmt/addons/src/package_2017_05/operations.rs

Large diffs are not rendered by default.

339 changes: 172 additions & 167 deletions services/mgmt/addons/src/package_2018_03/operations.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/mgmt/adhybridhealthservice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1.0"
snafu = "0.6"
thiserror = "1.0"
http = "0.2"
url = "2.2"

Expand Down
2,512 changes: 1,613 additions & 899 deletions services/mgmt/adhybridhealthservice/src/package_2014_01/operations.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/mgmt/adp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1.0"
snafu = "0.6"
thiserror = "1.0"
http = "0.2"
url = "2.2"

Expand Down
796 changes: 399 additions & 397 deletions services/mgmt/adp/src/package_2020_07_01_preview/operations.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/mgmt/advisor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1.0"
snafu = "0.6"
thiserror = "1.0"
http = "0.2"
url = "2.2"

Expand Down
293 changes: 191 additions & 102 deletions services/mgmt/advisor/src/package_2016_07_preview/operations.rs

Large diffs are not rendered by default.

295 changes: 193 additions & 102 deletions services/mgmt/advisor/src/package_2017_03/operations.rs

Large diffs are not rendered by default.

509 changes: 331 additions & 178 deletions services/mgmt/advisor/src/package_2017_04/operations.rs

Large diffs are not rendered by default.

993 changes: 492 additions & 501 deletions services/mgmt/advisor/src/package_2020_01/operations.rs

Large diffs are not rendered by default.

169 changes: 89 additions & 80 deletions services/mgmt/advisor/src/package_2020_07_preview/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,73 @@
#![allow(unused_variables)]
#![allow(unused_imports)]
use crate::models::*;
use snafu::{ResultExt, Snafu};
pub mod operations {
use crate::models::*;
use snafu::{ResultExt, Snafu};
pub async fn list(operation_config: &crate::OperationConfig) -> std::result::Result<OperationEntityListResult, list::Error> {
let http_client = operation_config.http_client();
let url_str = &format!("{}/providers/Microsoft.Advisor/operations", operation_config.base_path(),);
let mut url = url::Url::parse(url_str).context(list::ParseUrlError)?;
let mut url = url::Url::parse(url_str).map_err(|source| list::Error::ParseUrlError { source })?;
let mut req_builder = http::request::Builder::new();
req_builder = req_builder.method(http::Method::GET);
if let Some(token_credential) = operation_config.token_credential() {
let token_response = token_credential
.get_token(operation_config.token_credential_resource())
.await
.context(list::GetTokenError)?;
.map_err(|source| list::Error::GetTokenError { source })?;
req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
}
url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY);
req_builder = req_builder.uri(url.as_str());
let req = req_builder.body(req_body).context(list::BuildRequestError)?;
let rsp = http_client.execute_request(req).await.context(list::ExecuteRequestError)?;
let req = req_builder
.body(req_body)
.map_err(|source| list::Error::BuildRequestError { source })?;
let rsp = http_client
.execute_request(req)
.await
.map_err(|source| list::Error::ExecuteRequestError { source })?;
match rsp.status() {
http::StatusCode::OK => {
let rsp_body = rsp.body();
let rsp_value: OperationEntityListResult =
serde_json::from_slice(rsp_body).context(list::DeserializeError { body: rsp_body.clone() })?;
serde_json::from_slice(rsp_body).map_err(|source| list::Error::DeserializeError {
source,
body: rsp_body.clone(),
})?;
Ok(rsp_value)
}
status_code => {
let rsp_body = rsp.body();
list::UnexpectedResponse {
Err(list::Error::UnexpectedResponse {
status_code,
body: rsp_body.clone(),
}
.fail()
})
}
}
}
pub mod list {
use crate::{models, models::*};
use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
#[derive(Debug, thiserror :: Error)]
pub enum Error {
#[error("Unexpected HTTP status code {}", status_code)]
UnexpectedResponse { status_code: http::StatusCode, body: bytes::Bytes },
#[error("Failed to parse request URL: {}", source)]
ParseUrlError { source: url::ParseError },
#[error("Failed to build request: {}", source)]
BuildRequestError { source: http::Error },
#[error("Failed to execute request: {}", source)]
ExecuteRequestError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to serialize request body: {}", source)]
SerializeError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to deserialize response body: {}", source)]
DeserializeError { source: serde_json::Error, body: bytes::Bytes },
#[error("Failed to get access token: {}", source)]
GetTokenError { source: azure_core::errors::AzureError },
}
}
}
pub mod advisor_scores {
use crate::models::*;
use snafu::{ResultExt, Snafu};
pub async fn list(
operation_config: &crate::OperationConfig,
subscription_id: &str,
Expand All @@ -71,68 +80,68 @@ pub mod advisor_scores {
operation_config.base_path(),
subscription_id
);
let mut url = url::Url::parse(url_str).context(list::ParseUrlError)?;
let mut url = url::Url::parse(url_str).map_err(|source| list::Error::ParseUrlError { source })?;
let mut req_builder = http::request::Builder::new();
req_builder = req_builder.method(http::Method::GET);
if let Some(token_credential) = operation_config.token_credential() {
let token_response = token_credential
.get_token(operation_config.token_credential_resource())
.await
.context(list::GetTokenError)?;
.map_err(|source| list::Error::GetTokenError { source })?;
req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
}
let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY);
req_builder = req_builder.uri(url.as_str());
let req = req_builder.body(req_body).context(list::BuildRequestError)?;
let rsp = http_client.execute_request(req).await.context(list::ExecuteRequestError)?;
let req = req_builder
.body(req_body)
.map_err(|source| list::Error::BuildRequestError { source })?;
let rsp = http_client
.execute_request(req)
.await
.map_err(|source| list::Error::ExecuteRequestError { source })?;
match rsp.status() {
http::StatusCode::OK => {
let rsp_body = rsp.body();
let rsp_value: serde_json::Value =
serde_json::from_slice(rsp_body).context(list::DeserializeError { body: rsp_body.clone() })?;
let rsp_value: serde_json::Value = serde_json::from_slice(rsp_body).map_err(|source| list::Error::DeserializeError {
source,
body: rsp_body.clone(),
})?;
Ok(rsp_value)
}
status_code => {
let rsp_body = rsp.body();
let rsp_value: ArmErrorResponse =
serde_json::from_slice(rsp_body).context(list::DeserializeError { body: rsp_body.clone() })?;
list::DefaultResponse {
let rsp_value: ArmErrorResponse = serde_json::from_slice(rsp_body).map_err(|source| list::Error::DeserializeError {
source,
body: rsp_body.clone(),
})?;
Err(list::Error::DefaultResponse {
status_code,
value: rsp_value,
}
.fail()
})
}
}
}
pub mod list {
use crate::{models, models::*};
use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
#[derive(Debug, thiserror :: Error)]
pub enum Error {
#[error("HTTP status code {}", status_code)]
DefaultResponse {
status_code: http::StatusCode,
value: models::ArmErrorResponse,
},
ParseUrlError {
source: url::ParseError,
},
BuildRequestError {
source: http::Error,
},
ExecuteRequestError {
source: Box<dyn std::error::Error + Sync + Send>,
},
SerializeError {
source: Box<dyn std::error::Error + Sync + Send>,
},
DeserializeError {
source: serde_json::Error,
body: bytes::Bytes,
},
GetTokenError {
source: azure_core::errors::AzureError,
},
#[error("Failed to parse request URL: {}", source)]
ParseUrlError { source: url::ParseError },
#[error("Failed to build request: {}", source)]
BuildRequestError { source: http::Error },
#[error("Failed to execute request: {}", source)]
ExecuteRequestError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to serialize request body: {}", source)]
SerializeError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to deserialize response body: {}", source)]
DeserializeError { source: serde_json::Error, body: bytes::Bytes },
#[error("Failed to get access token: {}", source)]
GetTokenError { source: azure_core::errors::AzureError },
}
}
pub async fn get(
Expand All @@ -147,68 +156,68 @@ pub mod advisor_scores {
subscription_id,
name
);
let mut url = url::Url::parse(url_str).context(get::ParseUrlError)?;
let mut url = url::Url::parse(url_str).map_err(|source| get::Error::ParseUrlError { source })?;
let mut req_builder = http::request::Builder::new();
req_builder = req_builder.method(http::Method::GET);
if let Some(token_credential) = operation_config.token_credential() {
let token_response = token_credential
.get_token(operation_config.token_credential_resource())
.await
.context(get::GetTokenError)?;
.map_err(|source| get::Error::GetTokenError { source })?;
req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
}
let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY);
req_builder = req_builder.uri(url.as_str());
let req = req_builder.body(req_body).context(get::BuildRequestError)?;
let rsp = http_client.execute_request(req).await.context(get::ExecuteRequestError)?;
let req = req_builder
.body(req_body)
.map_err(|source| get::Error::BuildRequestError { source })?;
let rsp = http_client
.execute_request(req)
.await
.map_err(|source| get::Error::ExecuteRequestError { source })?;
match rsp.status() {
http::StatusCode::OK => {
let rsp_body = rsp.body();
let rsp_value: AdvisorScoreEntity =
serde_json::from_slice(rsp_body).context(get::DeserializeError { body: rsp_body.clone() })?;
let rsp_value: AdvisorScoreEntity = serde_json::from_slice(rsp_body).map_err(|source| get::Error::DeserializeError {
source,
body: rsp_body.clone(),
})?;
Ok(rsp_value)
}
status_code => {
let rsp_body = rsp.body();
let rsp_value: ArmErrorResponse =
serde_json::from_slice(rsp_body).context(get::DeserializeError { body: rsp_body.clone() })?;
get::DefaultResponse {
let rsp_value: ArmErrorResponse = serde_json::from_slice(rsp_body).map_err(|source| get::Error::DeserializeError {
source,
body: rsp_body.clone(),
})?;
Err(get::Error::DefaultResponse {
status_code,
value: rsp_value,
}
.fail()
})
}
}
}
pub mod get {
use crate::{models, models::*};
use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
#[derive(Debug, thiserror :: Error)]
pub enum Error {
#[error("HTTP status code {}", status_code)]
DefaultResponse {
status_code: http::StatusCode,
value: models::ArmErrorResponse,
},
ParseUrlError {
source: url::ParseError,
},
BuildRequestError {
source: http::Error,
},
ExecuteRequestError {
source: Box<dyn std::error::Error + Sync + Send>,
},
SerializeError {
source: Box<dyn std::error::Error + Sync + Send>,
},
DeserializeError {
source: serde_json::Error,
body: bytes::Bytes,
},
GetTokenError {
source: azure_core::errors::AzureError,
},
#[error("Failed to parse request URL: {}", source)]
ParseUrlError { source: url::ParseError },
#[error("Failed to build request: {}", source)]
BuildRequestError { source: http::Error },
#[error("Failed to execute request: {}", source)]
ExecuteRequestError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to serialize request body: {}", source)]
SerializeError { source: Box<dyn std::error::Error + Sync + Send> },
#[error("Failed to deserialize response body: {}", source)]
DeserializeError { source: serde_json::Error, body: bytes::Bytes },
#[error("Failed to get access token: {}", source)]
GetTokenError { source: azure_core::errors::AzureError },
}
}
}
2 changes: 1 addition & 1 deletion services/mgmt/alertsmanagement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json"] }
bytes = "1.0"
snafu = "0.6"
thiserror = "1.0"
http = "0.2"
url = "2.2"

Expand Down
Loading