Skip to content

Commit

Permalink
Remove unnecessary map_kind
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Jun 27, 2022
1 parent 9afd7c4 commit f03f4c7
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 125 deletions.
4 changes: 2 additions & 2 deletions sdk/data_tables/src/requests/submit_transaction_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{prelude::*, responses::*};
use azure_core::{
error::{Error, ErrorKind, ResultExt},
error::{Error, ErrorKind},
prelude::*,
};
use http::method::Method;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<'a> SubmitTransactionBuilder<'a> {

self.timeout.append_to_url_query(&mut url);

let payload = batch.to_string().map_kind(ErrorKind::DataConversion)?;
let payload = batch.to_string()?;

let mut request = self.partition_key_client.prepare_request(
url.as_str(),
Expand Down
3 changes: 1 addition & 2 deletions sdk/identity/src/refresh_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ pub async fn exchange(
} else {
return Err(
ErrorKind::http_response_from_body(rsp_status.as_u16(), &rsp_body).into_error(),
)
.map_kind(ErrorKind::Credential);
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl TokenCredential for ImdsManagedIdentityCredential {
ErrorKind::http_response_from_body(rsp_status.as_u16(), &rsp_body)
.into_error(),
)
.map_kind(ErrorKind::Credential)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/src/core/xml.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use azure_core::error::{Error, ErrorKind, ResultExt};
use azure_core::error::{ErrorKind, ResultExt};

/// The UTF8 [byte order marker](https://en.wikipedia.org/wiki/Byte_order_mark)
const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF];

/// Reads the XML from bytes.
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> Result<T, Error> {
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> azure_core::Result<T> {
serde_xml_rs::from_reader(slice_bom(body))
.context(ErrorKind::DataConversion, "failed to deserialize xml")
}
Expand Down
10 changes: 2 additions & 8 deletions sdk/storage_blobs/src/blob/operations/put_block.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
};
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::{headers::consistency_from_headers, ConsistencyCRC64, ConsistencyMD5};
use bytes::Bytes;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -74,8 +69,7 @@ pub struct PutBlockResponse {

impl PutBlockResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockResponse> {
let (content_md5, content_crc64) =
consistency_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let (content_md5, content_crc64) = consistency_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
4 changes: 1 addition & 3 deletions sdk/storage_blobs/src/blob/operations/put_block_blob.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
Expand Down Expand Up @@ -105,8 +104,7 @@ impl PutBlockBlobResponse {
pub fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockBlobResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let (content_md5, content_crc64) =
consistency_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let (content_md5, content_crc64) = consistency_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage_blobs/src/blob/operations/put_block_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
Expand Down Expand Up @@ -115,7 +114,7 @@ impl PutBlockListResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockListResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let content_md5 = content_md5_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let content_md5 = content_md5_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage_blobs/src/blob/operations/update_page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{prelude::*, BA512Range};
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
Expand Down Expand Up @@ -93,7 +92,7 @@ impl UpdatePageResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<UpdatePageResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let content_md5 = content_md5_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let content_md5 = content_md5_from_headers(headers)?;
let sequence_number = sequence_number_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
Expand Down
48 changes: 14 additions & 34 deletions sdk/storage_blobs/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,39 +124,19 @@ impl Container {
}

fn parse(elem: &Element) -> azure_core::Result<Container> {
let name = cast_must::<String>(elem, &["Name"]).map_kind(ErrorKind::DataConversion)?;
let last_modified = cast_must::<DateTime<Utc>>(elem, &["Properties", "Last-Modified"])
.map_kind(ErrorKind::DataConversion)?;
let e_tag = cast_must::<String>(elem, &["Properties", "Etag"])
.map_kind(ErrorKind::DataConversion)?;

let lease_state = cast_must::<LeaseState>(elem, &["Properties", "LeaseState"])
.map_kind(ErrorKind::DataConversion)?;

let lease_duration = cast_optional::<LeaseDuration>(elem, &["Properties", "LeaseDuration"])
.map_kind(ErrorKind::DataConversion)?;

let lease_status = cast_must::<LeaseStatus>(elem, &["Properties", "LeaseStatus"])
.map_kind(ErrorKind::DataConversion)?;

let name = cast_must(elem, &["Name"]).map_kind(ErrorKind::DataConversion)?;
let last_modified = cast_must(elem, &["Properties", "Last-Modified"])?;
let e_tag = cast_must(elem, &["Properties", "Etag"])?;
let lease_state = cast_must(elem, &["Properties", "LeaseState"])?;
let lease_duration = cast_optional(elem, &["Properties", "LeaseDuration"])?;
let lease_status = cast_must(elem, &["Properties", "LeaseStatus"])?;
let public_access =
match cast_optional::<PublicAccess>(elem, &["Properties", "PublicAccess"])
.map_kind(ErrorKind::DataConversion)?
{
Some(pa) => pa,
None => PublicAccess::None,
};

let has_immutability_policy =
cast_must::<bool>(elem, &["Properties", "HasImmutabilityPolicy"])
.map_kind(ErrorKind::DataConversion)?;
let has_legal_hold = cast_must::<bool>(elem, &["Properties", "HasLegalHold"])
.map_kind(ErrorKind::DataConversion)?;

cast_optional(elem, &["Properties", "PublicAccess"])?.unwrap_or(PublicAccess::None);
let has_immutability_policy = cast_must(elem, &["Properties", "HasImmutabilityPolicy"])?;
let has_legal_hold = cast_must(elem, &["Properties", "HasLegalHold"])?;
let metadata = {
let mut hm = HashMap::new();
let metadata =
traverse(elem, &["Metadata"], true).map_kind(ErrorKind::DataConversion)?;
let metadata = traverse(elem, &["Metadata"], true)?;

for m in metadata {
for key in &m.children {
Expand All @@ -170,18 +150,18 @@ impl Container {
}
};

let key = elem.name.to_owned();

if elem.children.is_empty() {
return Err(Error::message(
ErrorKind::DataConversion,
"Metadata node should not be empty",
));
}

let key = elem.name.clone();

let content = {
match elem.children[0] {
Xml::CharacterNode(ref content) => content.to_owned(),
match &elem.children[0] {
Xml::CharacterNode(content) => content.clone(),
_ => {
return Err(Error::message(ErrorKind::DataConversion,
"Metadata node should contain a CharacterNode with metadata value",
Expand Down
5 changes: 2 additions & 3 deletions sdk/storage_blobs/src/container/operations/list_blobs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{blob::Blob, prelude::*};
use azure_core::{
collect_pinned_stream,
error::{Error, ErrorKind, ResultExt},
error::Error,
headers::{date_from_headers, request_id_from_headers},
prelude::*,
Pageable, RequestId, Response as AzureResponse,
Expand Down Expand Up @@ -166,8 +166,7 @@ impl ListBlobsResponse {
let (_, headers, body) = response.deconstruct();
let body = collect_pinned_stream(body).await?;

let list_blobs_response_internal: ListBlobsResponseInternal =
read_xml(&body).map_kind(ErrorKind::DataConversion)?;
let list_blobs_response_internal: ListBlobsResponseInternal = read_xml(&body)?;

let next_marker = match list_blobs_response_internal.next_marker {
Some(ref nm) if nm.is_empty() => None,
Expand Down
19 changes: 7 additions & 12 deletions sdk/storage_blobs/src/container/operations/list_containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,20 @@ pub struct ListContainersResponse {

impl ListContainersResponse {
async fn try_from(response: Response) -> azure_core::Result<Self> {
let body = response.into_body().await;
let body = std::str::from_utf8(&body)?;

let body = response.into_body_string().await;
let elem: Element = body.parse().map_kind(ErrorKind::Other)?;

let mut containers = Vec::new();

for container in
traverse(&elem, &["Containers", "Container"], true).map_kind(ErrorKind::Other)?
{
for container in traverse(&elem, &["Containers", "Container"], true)? {
containers.push(Container::parse(container)?);
}

let next_marker =
match cast_optional::<String>(&elem, &["NextMarker"]).map_kind(ErrorKind::Other)? {
Some(ref nm) if nm.is_empty() => None,
Some(nm) => Some(nm),
None => None,
};
let next_marker = match cast_optional::<String>(&elem, &["NextMarker"])? {
Some(nm) if nm.is_empty() => None,
Some(nm) => Some(nm),
None => None,
};

Ok(Self {
containers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::clients::FileSystemClient;
use crate::{util::*, Properties};
use azure_core::error::ResultExt;
use azure_core::{
error::ErrorKind,
headers::{etag_from_headers, last_modified_from_headers},
AppendToUrlQuery, Etag, Response as HttpResponse,
};
Expand Down Expand Up @@ -79,7 +77,7 @@ impl GetFileSystemPropertiesResponse {
etag: Etag::from(etag_from_headers(&headers)?),
last_modified: last_modified_from_headers(&headers)?,
namespace_enabled: namespace_enabled_from_headers(&headers)?,
properties: (&headers).try_into().map_kind(ErrorKind::DataConversion)?,
properties: (&headers).try_into()?,
})
}
}
11 changes: 2 additions & 9 deletions sdk/storage_datalake/src/operations/file_systems_list.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use crate::clients::DataLakeClient;
use crate::file_system::{FileSystem, FileSystemList};
use azure_core::error::ResultExt;
use azure_core::{
collect_pinned_stream,
error::{Error, ErrorKind},
prelude::*,
Pageable, Response,
};
use azure_core::{collect_pinned_stream, error::Error, prelude::*, Pageable, Response};
use azure_core::{AppendToUrlQuery, Request};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;
Expand Down Expand Up @@ -94,8 +88,7 @@ impl ListFileSystemsResponse {
pub(crate) async fn try_from(response: Response) -> azure_core::Result<Self> {
let (_status_code, headers, pinned_stream) = response.deconstruct();
let body = collect_pinned_stream(pinned_stream).await?;
let file_system_list: FileSystemList =
body.try_into().map_kind(ErrorKind::DataConversion)?;
let file_system_list: FileSystemList = body.try_into()?;

Ok(ListFileSystemsResponse {
common_storage_response_headers: (&headers).try_into()?,
Expand Down
2 changes: 0 additions & 2 deletions sdk/storage_queues/src/clients/queue_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{operations::*, QueueStoredAccessPolicy};
use azure_core::{
error::{ErrorKind, ResultExt},
prelude::*,
Context, Request, Response,
};
Expand Down Expand Up @@ -59,7 +58,6 @@ impl QueueClient {
{
self.storage_client
.queue_url_with_segments(Some(self.queue_name.as_str()).into_iter().chain(segments))
.map_kind(ErrorKind::DataConversion)
}

pub fn queue_name(&self) -> &str {
Expand Down
2 changes: 0 additions & 2 deletions sdk/storage_queues/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate azure_core;
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage_queues/src/operations/get_messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{clients::QueueClient, prelude::*, PopReceipt};
use azure_core::{
collect_pinned_stream,
error::{ErrorKind, ResultExt},
prelude::*,
Context, Response as AzureResponse,
};
Expand Down Expand Up @@ -115,7 +114,7 @@ struct MessageList {

impl GetMessagesResponse {
fn parse_messages(body: &[u8]) -> azure_core::Result<Vec<Message>> {
let response: MessageList = read_xml(body).map_kind(ErrorKind::DataConversion)?;
let response: MessageList = read_xml(body)?;
Ok(response.messages.unwrap_or_default())
}

Expand Down
12 changes: 3 additions & 9 deletions sdk/storage_queues/src/operations/get_queue_acl.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::{clients::QueueClient, QueueStoredAccessPolicy};
use azure_core::{
collect_pinned_stream,
error::{ErrorKind, ResultExt},
prelude::*,
Context, Response as AzureResponse,
};
use azure_core::{collect_pinned_stream, prelude::*, Context, Response as AzureResponse};
use azure_storage::{core::headers::CommonStorageResponseHeaders, StoredAccessPolicyList};
use http::method::Method;
use std::convert::TryInto;
Expand Down Expand Up @@ -76,11 +71,10 @@ impl GetQueueACLResponse {
let body = collect_pinned_stream(body).await?;

let a: azure_core::Result<Vec<QueueStoredAccessPolicy>> =
StoredAccessPolicyList::from_xml(&body)
.map_kind(ErrorKind::DataConversion)?
StoredAccessPolicyList::from_xml(&body)?
.stored_access
.into_iter()
.map(|sap| sap.try_into().map_kind(ErrorKind::DataConversion))
.map(|sap| sap.try_into())
.collect();

Ok(GetQueueACLResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{QueueServiceClient, QueueServiceProperties};
use azure_core::{
collect_pinned_stream,
error::{ErrorKind, ResultExt},
prelude::*,
Context, Response as AzureResponse,
};
Expand Down Expand Up @@ -82,8 +81,7 @@ impl GetQueueServicePropertiesResponse {
let (_, headers, body) = response.deconstruct();
let body = collect_pinned_stream(body).await?;

let queue_service_properties: QueueServiceProperties =
read_xml(&body).map_kind(ErrorKind::DataConversion)?;
let queue_service_properties: QueueServiceProperties = read_xml(&body)?;

Ok(GetQueueServicePropertiesResponse {
common_storage_response_headers: (&headers).try_into()?,
Expand Down
6 changes: 1 addition & 5 deletions sdk/storage_queues/src/operations/get_queue_service_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ impl GetQueueServiceStatsResponse {
let (_, headers, body) = response.deconstruct();
let body = collect_pinned_stream(body).await?;

debug!("headers == {:?}", headers);
debug!("body == {:#?}", body);
let response: GetQueueServiceStatsResponseInternal =
read_xml(&body).map_kind(ErrorKind::DataConversion)?;
debug!("deserde == {:#?}", response);
let response: GetQueueServiceStatsResponseInternal = read_xml(&body)?;

Ok(GetQueueServiceStatsResponse {
common_storage_response_headers: (&headers).try_into()?,
Expand Down
Loading

0 comments on commit f03f4c7

Please sign in to comment.