Skip to content

Commit 334a748

Browse files
authored
Migrate storage_datalake to azure_core::error::Error (#795)
1 parent 490d34b commit 334a748

19 files changed

+94
-58
lines changed

sdk/storage_datalake/src/clients/directory_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::request_options::*;
33
use crate::{
44
clients::{DataLakeClient, FileSystemClient},
55
prelude::PathClient,
6-
Properties, Result,
6+
Properties,
77
};
88
use azure_core::prelude::IfMatchCondition;
9-
use azure_core::{ClientOptions, Context, Pipeline};
9+
use azure_core::{error::Result, ClientOptions, Context, Pipeline};
1010
use azure_storage::core::storage_shared_key_credential::StorageSharedKeyCredential;
1111
use url::Url;
1212

sdk/storage_datalake/src/clients/file_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{DataLakeClient, FileSystemClient, PathClient};
2-
use crate::{operations::*, request_options::*, Properties, Result};
2+
use crate::{operations::*, request_options::*, Properties};
3+
use azure_core::error::Result;
34
use azure_core::prelude::IfMatchCondition;
45
use azure_core::{ClientOptions, Context, Pipeline};
56
use azure_storage::core::storage_shared_key_credential::StorageSharedKeyCredential;

sdk/storage_datalake/src/clients/file_system_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{DataLakeClient, DirectoryClient, FileClient};
22
use crate::operations::*;
3-
use crate::{Properties, Result};
4-
use azure_core::{ClientOptions, Context, Pipeline};
3+
use crate::Properties;
4+
use azure_core::{error::Result, ClientOptions, Context, Pipeline};
55
use azure_storage::core::storage_shared_key_credential::StorageSharedKeyCredential;
66
use url::Url;
77

sdk/storage_datalake/src/clients/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use file_client::FileClient;
1111
pub use file_system_client::FileSystemClient;
1212

1313
pub trait PathClient: Debug + Clone + Send + Sync {
14-
fn url(&self) -> crate::Result<url::Url>;
14+
fn url(&self) -> azure_core::error::Result<url::Url>;
1515
fn prepare_request(&self, uri: &str, http_method: http::Method) -> azure_core::Request;
1616
fn pipeline(&self) -> &azure_core::Pipeline;
1717
fn context(&self) -> &azure_core::Context;

sdk/storage_datalake/src/file_system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) struct PathList {
4646
}
4747

4848
impl TryFrom<Bytes> for PathList {
49-
type Error = crate::Error;
49+
type Error = azure_core::error::Error;
5050

5151
fn try_from(response: Bytes) -> Result<Self, Self::Error> {
5252
Ok(serde_json::from_slice::<PathList>(response.as_ref())?)

sdk/storage_datalake/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ mod properties;
2525
pub mod request_options;
2626
mod util;
2727

28-
pub use azure_storage::{Error, Result};
28+
pub use azure_core::error::{Error, Result};
2929
pub use file_system::FileSystem;
3030
pub use properties::Properties;

sdk/storage_datalake/src/operations/file_system_create.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::clients::FileSystemClient;
22
use crate::util::*;
33
use crate::Properties;
4-
use azure_core::prelude::*;
4+
use azure_core::prelude::{ClientRequestId, ContentLength, Timeout};
55
use azure_core::{
6+
error::Result,
67
headers::{etag_from_headers, last_modified_from_headers},
78
AppendToUrlQuery, Etag, Response as HttpResponse,
89
};
@@ -11,8 +12,7 @@ use chrono::{DateTime, Utc};
1112
use std::convert::TryInto;
1213

1314
/// A future of a create file system response
14-
type CreateFileSystem =
15-
futures::future::BoxFuture<'static, crate::Result<CreateFileSystemResponse>>;
15+
type CreateFileSystem = futures::future::BoxFuture<'static, Result<CreateFileSystemResponse>>;
1616

1717
#[derive(Debug, Clone)]
1818
pub struct CreateFileSystemBuilder {
@@ -73,7 +73,7 @@ pub struct CreateFileSystemResponse {
7373
}
7474

7575
impl CreateFileSystemResponse {
76-
pub async fn try_from(response: HttpResponse) -> crate::Result<Self> {
76+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
7777
let (_status_code, headers, _pinned_stream) = response.deconstruct();
7878

7979
Ok(Self {

sdk/storage_datalake/src/operations/file_system_delete.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::clients::FileSystemClient;
22
use azure_core::prelude::*;
3-
use azure_core::{AppendToUrlQuery, Response as HttpResponse};
3+
use azure_core::{error::Result, AppendToUrlQuery, Response as HttpResponse};
44
use azure_storage::core::headers::CommonStorageResponseHeaders;
55
use std::convert::TryInto;
66

77
/// A future of a create file system response
8-
type DeleteFileSystem =
9-
futures::future::BoxFuture<'static, crate::Result<DeleteFileSystemResponse>>;
8+
type DeleteFileSystem = futures::future::BoxFuture<'static, Result<DeleteFileSystemResponse>>;
109

1110
#[derive(Debug, Clone)]
1211
pub struct DeleteFileSystemBuilder {
@@ -66,7 +65,7 @@ pub struct DeleteFileSystemResponse {
6665
}
6766

6867
impl DeleteFileSystemResponse {
69-
pub async fn try_from(response: HttpResponse) -> crate::Result<Self> {
68+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
7069
let (_status_code, headers, _pinned_stream) = response.deconstruct();
7170

7271
Ok(Self {

sdk/storage_datalake/src/operations/file_system_get_properties.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::clients::FileSystemClient;
22
use crate::{util::*, Properties};
3+
use azure_core::error::ResultExt;
34
use azure_core::prelude::*;
45
use azure_core::{
6+
error::{ErrorKind, Result},
57
headers::{etag_from_headers, last_modified_from_headers},
68
AppendToUrlQuery, Etag, Response as HttpResponse,
79
};
@@ -11,7 +13,7 @@ use std::convert::TryInto;
1113

1214
/// A future of a file system get properties response
1315
type GetFileSystemProperties =
14-
futures::future::BoxFuture<'static, crate::Result<GetFileSystemPropertiesResponse>>;
16+
futures::future::BoxFuture<'static, Result<GetFileSystemPropertiesResponse>>;
1517

1618
#[derive(Debug, Clone)]
1719
pub struct GetFileSystemPropertiesBuilder {
@@ -71,15 +73,15 @@ pub struct GetFileSystemPropertiesResponse {
7173
}
7274

7375
impl GetFileSystemPropertiesResponse {
74-
pub async fn try_from(response: HttpResponse) -> crate::Result<Self> {
76+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
7577
let (_status_code, headers, _pinned_stream) = response.deconstruct();
7678

7779
Ok(GetFileSystemPropertiesResponse {
7880
common_storage_response_headers: (&headers).try_into()?,
7981
etag: Etag::from(etag_from_headers(&headers)?),
8082
last_modified: last_modified_from_headers(&headers)?,
8183
namespace_enabled: namespace_enabled_from_headers(&headers)?,
82-
properties: (&headers).try_into()?,
84+
properties: (&headers).try_into().map_kind(ErrorKind::DataConversion)?,
8385
})
8486
}
8587
}

sdk/storage_datalake/src/operations/file_system_set_properties.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::clients::FileSystemClient;
22
use crate::Properties;
33
use azure_core::prelude::*;
44
use azure_core::{
5+
error::Result,
56
headers::{etag_from_headers, last_modified_from_headers},
67
AppendToUrlQuery, Etag, Response as HttpResponse,
78
};
@@ -11,7 +12,7 @@ use std::convert::TryInto;
1112

1213
/// A future of a file system set properties response
1314
type SetFileSystemProperties =
14-
futures::future::BoxFuture<'static, crate::Result<SetFileSystemPropertiesResponse>>;
15+
futures::future::BoxFuture<'static, Result<SetFileSystemPropertiesResponse>>;
1516

1617
#[derive(Debug, Clone)]
1718
pub struct SetFileSystemPropertiesBuilder {
@@ -77,7 +78,7 @@ pub struct SetFileSystemPropertiesResponse {
7778
}
7879

7980
impl SetFileSystemPropertiesResponse {
80-
pub async fn try_from(response: HttpResponse) -> crate::Result<Self> {
81+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
8182
let (_status_code, headers, _pinned_stream) = response.deconstruct();
8283

8384
Ok(SetFileSystemPropertiesResponse {

sdk/storage_datalake/src/operations/file_systems_list.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
use crate::clients::DataLakeClient;
22
use crate::file_system::{FileSystem, FileSystemList};
3+
use azure_core::error::ResultExt;
34
use azure_core::AppendToUrlQuery;
4-
use azure_core::{collect_pinned_stream, prelude::*, Pageable, Response};
5+
use azure_core::{
6+
collect_pinned_stream,
7+
error::{ErrorKind, Result},
8+
prelude::*,
9+
Pageable, Response,
10+
};
511
use azure_storage::core::headers::CommonStorageResponseHeaders;
612
use std::convert::TryInto;
713

@@ -88,10 +94,11 @@ pub struct ListFileSystemsResponse {
8894
}
8995

9096
impl ListFileSystemsResponse {
91-
pub(crate) async fn try_from(response: Response) -> crate::Result<Self> {
97+
pub(crate) async fn try_from(response: Response) -> Result<Self> {
9298
let (_status_code, headers, pinned_stream) = response.deconstruct();
9399
let body = collect_pinned_stream(pinned_stream).await?;
94-
let file_system_list: FileSystemList = body.try_into()?;
100+
let file_system_list: FileSystemList =
101+
body.try_into().map_kind(ErrorKind::DataConversion)?;
95102

96103
Ok(ListFileSystemsResponse {
97104
common_storage_response_headers: (&headers).try_into()?,

sdk/storage_datalake/src/operations/path_delete.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::clients::PathClient;
22
use crate::request_options::*;
33
use azure_core::prelude::*;
4-
use azure_core::{AppendToUrlQuery, Response as HttpResponse};
4+
use azure_core::{error::Result, AppendToUrlQuery, Response as HttpResponse};
55
use azure_storage::core::headers::CommonStorageResponseHeaders;
66
use std::convert::TryInto;
77

88
/// A future of a delete file response
9-
type PutPath = futures::future::BoxFuture<'static, crate::Result<DeletePathResponse>>;
9+
type PutPath = futures::future::BoxFuture<'static, Result<DeletePathResponse>>;
1010

1111
#[derive(Debug, Clone)]
1212
pub struct DeletePathBuilder<C>
@@ -86,7 +86,7 @@ pub struct DeletePathResponse {
8686
}
8787

8888
impl DeletePathResponse {
89-
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> {
89+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
9090
let (_status_code, headers, _pinned_stream) = response.deconstruct();
9191

9292
Ok(Self {

sdk/storage_datalake/src/operations/path_get.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
use crate::clients::{FileClient, PathClient};
2+
use azure_core::error::ResultExt;
23
use azure_core::headers::{etag_from_headers, last_modified_from_headers};
34
use azure_core::prelude::*;
4-
use azure_core::{collect_pinned_stream, AppendToUrlQuery, Response as HttpResponse};
5+
use azure_core::{
6+
collect_pinned_stream,
7+
error::{ErrorKind, Result},
8+
AppendToUrlQuery, Response as HttpResponse,
9+
};
510
use azure_storage::core::headers::CommonStorageResponseHeaders;
611
use bytes::Bytes;
712
use chrono::{DateTime, Utc};
813
use std::convert::TryInto;
914
use std::str::FromStr;
1015

1116
/// A future of a delete file response
12-
type GetFile = futures::future::BoxFuture<'static, crate::Result<GetFileResponse>>;
17+
type GetFile = futures::future::BoxFuture<'static, Result<GetFileResponse>>;
1318

1419
#[derive(Debug, Clone)]
1520
pub struct GetFileBuilder {
@@ -87,13 +92,16 @@ pub struct GetFileResponse {
8792
}
8893

8994
impl GetFileResponse {
90-
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> {
95+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
9196
let (_status_code, headers, pinned_stream) = response.deconstruct();
9297

9398
let data = collect_pinned_stream(pinned_stream).await?;
9499
let content_range_header = headers.get(http::header::CONTENT_RANGE);
95100
let content_range = match content_range_header {
96-
Some(hv) => Some(ContentRange::from_str(hv.to_str()?)?),
101+
Some(hv) => Some(
102+
ContentRange::from_str(hv.to_str().map_kind(ErrorKind::DataConversion)?)
103+
.map_kind(ErrorKind::DataConversion)?,
104+
),
97105
None => None,
98106
};
99107

sdk/storage_datalake/src/operations/path_head.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use crate::{clients::PathClient, request_options::*, Properties};
2+
use azure_core::error::ResultExt;
23
use azure_core::headers::{
34
etag_from_headers, get_option_str_from_headers, last_modified_from_headers,
45
};
56
use azure_core::prelude::*;
6-
use azure_core::{AppendToUrlQuery, Response as HttpResponse};
7+
use azure_core::{
8+
error::{ErrorKind, Result},
9+
AppendToUrlQuery, Response as HttpResponse,
10+
};
711
use azure_storage::core::headers::CommonStorageResponseHeaders;
812
use chrono::{DateTime, Utc};
913
use std::convert::TryInto;
1014

1115
/// A future of a delete file response
12-
type HeadPath = futures::future::BoxFuture<'static, crate::Result<HeadPathResponse>>;
16+
type HeadPath = futures::future::BoxFuture<'static, Result<HeadPathResponse>>;
1317

1418
#[derive(Debug, Clone)]
1519
pub struct HeadPathBuilder<C>
@@ -94,7 +98,7 @@ pub struct HeadPathResponse {
9498
}
9599

96100
impl HeadPathResponse {
97-
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> {
101+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
98102
let headers = response.headers();
99103

100104
Ok(Self {
@@ -103,7 +107,8 @@ impl HeadPathResponse {
103107
last_modified: last_modified_from_headers(headers)?,
104108
properties: get_option_str_from_headers(headers, azure_core::headers::PROPERTIES)?
105109
.map(Properties::try_from)
106-
.transpose()?,
110+
.transpose()
111+
.map_kind(ErrorKind::DataConversion)?,
107112
acl: get_option_str_from_headers(headers, azure_core::headers::ACL)?
108113
.map(|s| s.to_owned()),
109114
})

sdk/storage_datalake/src/operations/path_list.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ use crate::{
33
file_system::{Path, PathList},
44
request_options::*,
55
};
6-
use azure_core::{collect_pinned_stream, prelude::*, AppendToUrlQuery, Pageable, Response};
6+
use azure_core::{
7+
collect_pinned_stream,
8+
error::{Error, ErrorKind, Result},
9+
prelude::*,
10+
AppendToUrlQuery, Pageable, Response,
11+
};
712
use azure_storage::core::headers::CommonStorageResponseHeaders;
813
use std::convert::TryInto;
914

1015
/// A future of a delete file response
11-
type ListPaths = Pageable<ListPathsResponse, azure_core::Error>;
16+
type ListPaths = Pageable<ListPathsResponse, Error>;
1217

1318
#[derive(Debug, Clone)]
1419
pub struct ListPathsBuilder {
@@ -82,7 +87,7 @@ impl ListPathsBuilder {
8287

8388
match ListPathsResponse::try_from(response).await {
8489
Ok(r) => Ok(r),
85-
Err(e) => Err(azure_core::Error::Other(Box::new(e))),
90+
Err(e) => Err(Error::new(ErrorKind::DataConversion, e)),
8691
}
8792
}
8893
};
@@ -99,7 +104,7 @@ pub struct ListPathsResponse {
99104
}
100105

101106
impl ListPathsResponse {
102-
pub(crate) async fn try_from(response: Response) -> crate::Result<Self> {
107+
pub(crate) async fn try_from(response: Response) -> Result<Self> {
103108
let (_status_code, headers, pinned_stream) = response.deconstruct();
104109
let body = collect_pinned_stream(pinned_stream).await?;
105110
let path_list: PathList = body.try_into()?;

sdk/storage_datalake/src/operations/path_patch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use crate::request_options::*;
33
use crate::Properties;
44
use azure_core::headers::{etag_from_headers, last_modified_from_headers};
55
use azure_core::prelude::*;
6-
use azure_core::{AppendToUrlQuery, Response as HttpResponse};
6+
use azure_core::{error::Result, AppendToUrlQuery, Response as HttpResponse};
77
use azure_storage::core::headers::CommonStorageResponseHeaders;
88
use bytes::Bytes;
99
use chrono::{DateTime, Utc};
1010
use futures::future::BoxFuture;
1111
use std::convert::TryInto;
1212

1313
/// A future of a patch file response
14-
type PatchPath = BoxFuture<'static, crate::Result<PatchPathResponse>>;
14+
type PatchPath = BoxFuture<'static, Result<PatchPathResponse>>;
1515

1616
#[derive(Debug, Clone)]
1717
pub struct PatchPathBuilder<C>
@@ -120,7 +120,7 @@ pub struct PatchPathResponse {
120120
}
121121

122122
impl PatchPathResponse {
123-
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> {
123+
pub async fn try_from(response: HttpResponse) -> Result<Self> {
124124
let (_status_code, headers, _pinned_stream) = response.deconstruct();
125125

126126
let etag = match etag_from_headers(&headers) {

0 commit comments

Comments
 (0)