Skip to content

Commit bc7faed

Browse files
authored
azure_cosmos::Error & azure_storage::Error (#285)
1 parent ea7b3f5 commit bc7faed

File tree

170 files changed

+395
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+395
-556
lines changed

sdk/core/src/errors.rs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub enum ParsingError {
1616
#[non_exhaustive]
1717
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
1818
pub enum ParseError {
19-
#[error("Expected token \"{}\" not found", 0)]
19+
#[error("Expected token \"{0}\" not found")]
2020
TokenNotFound(String),
21-
#[error("Expected split char \'{}\' not found", 0)]
21+
#[error("Expected split char \'{0}\' not found")]
2222
SplitNotFound(char),
2323
#[error("Parse int error {0}")]
2424
ParseIntError(std::num::ParseIntError),
@@ -174,30 +174,10 @@ pub enum Error {
174174
GetTokenError(Box<dyn std::error::Error + Send + Sync>),
175175
#[error("http error: {0}")]
176176
HttpError(#[from] HttpError),
177-
#[error("{}-{} is not 512 byte aligned", start, end)]
178-
PageNot512ByteAlignedError { start: u64, end: u64 },
179-
#[error("{} is not 512 byte aligned", size)]
180-
Not512ByteAlignedError { size: u64 },
181-
#[error("Operation not supported. Operation == {0}, reason == {1}")]
182-
OperationNotSupported(String, String),
183177
#[error("parse bool error: {0}")]
184178
ParseBoolError(#[from] std::str::ParseBoolError),
185179
#[error("to str error: {0}")]
186180
ToStrError(#[from] http::header::ToStrError),
187-
#[error("json error: {0}")]
188-
JSONError(#[from] serde_json::Error),
189-
#[error("Permission error: {0}")]
190-
PermissionError(#[from] PermissionError),
191-
#[error("IO error: {0}")]
192-
IOError(#[from] std::io::Error),
193-
#[error("UnexpectedXMLError: {0}")]
194-
UnexpectedXMLError(String),
195-
#[error("Azure Path parse error: {0}")]
196-
AzurePathParseError(#[from] AzurePathParseError),
197-
#[error("UnexpectedHTTPResult error: {0:?}")]
198-
UnexpectedHTTPResult(UnexpectedHTTPResult),
199-
#[error("UnexpectedValue error: {0:?}")]
200-
UnexpectedValue(UnexpectedValue),
201181
#[error("Header not found: {0}")]
202182
HeaderNotFound(String),
203183
#[error("At least one of these headers must be present: {0:?}")]
@@ -211,45 +191,14 @@ pub enum Error {
211191
expected_parameter: String,
212192
url: url::Url,
213193
},
214-
#[error("Traversing error: {0}")]
215-
ResponseParsingError(#[from] TraversingError),
216194
#[error("Parse int error: {0}")]
217195
ParseIntError(#[from] std::num::ParseIntError),
218-
#[error("Parse float error: {0}")]
219-
ParseFloatError(#[from] std::num::ParseFloatError),
220-
#[error("Parse error: {0}")]
221-
ParseError(#[from] ParseError),
222-
#[error("Parsing error: {0}")]
223-
ParsingError(#[from] ParsingError),
224-
#[error("Input parameters error: {0}")]
225-
InputParametersError(String),
226-
#[error("URL parse error: {0}")]
227-
UrlParseError(#[from] url::ParseError),
228196
#[error("Error preparing HTTP request: {0}")]
229197
HttpPrepareError(#[from] http::Error),
230198
#[error("uuid error: {0}")]
231199
ParseUuidError(#[from] uuid::Error),
232200
#[error("Chrono parser error: {0}")]
233201
ChronoParserError(#[from] chrono::ParseError),
234-
#[error("UTF8 conversion error: {0}")]
235-
Utf8Error(#[from] std::str::Utf8Error),
236-
#[error("FromUTF8 error: {0}")]
237-
FromUtf8Error(#[from] std::string::FromUtf8Error),
238-
#[error("A required header is missing: {0}")]
239-
MissingHeaderError(String),
240-
#[error(
241-
"An expected JSON node is missing: {} of expected type {}",
242-
value,
243-
expected_type
244-
)]
245-
MissingValueError {
246-
value: String,
247-
expected_type: String,
248-
},
249-
#[error("Invalid status code: {:?}", 0)]
250-
InvalidStatusCode(#[from] http::status::InvalidStatusCode),
251-
#[error("Error parsing the transaction response: {:?}", 0)]
252-
TransactionResponseParseError(String),
253202
}
254203

255204
#[non_exhaustive]
@@ -273,7 +222,7 @@ pub enum TraversingError {
273222
ParseIntError(#[from] std::num::ParseIntError),
274223
#[error("Generic parse error: {0}")]
275224
GenericParseError(String),
276-
#[error("Parsing error: {:?}", 0)]
225+
#[error("Parsing error: {0:?}")]
277226
ParsingError(#[from] ParsingError),
278227
}
279228

sdk/cosmos/examples/collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
1212
// This is how you construct an authorization token.
1313
// Remember to pick the correct token type.
1414
// Here we assume master.
15-
// Most methods return a ```Result<_, CosmosError>```.
16-
// ```CosmosError``` is an enum union of all the possible underlying
15+
// Most methods return a ```Result<_, azure_cosmos::Error```.
16+
// ```azure_cosmos::Error``` is an enum union of all the possible underlying
1717
// errors, plus Azure specific ones. For example if a REST call returns the
1818
// unexpected result (ie NotFound instead of Ok) we return an Err telling
1919
// you that.

sdk/cosmos/examples/create_delete_database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
2121
// This is how you construct an authorization token.
2222
// Remember to pick the correct token type.
2323
// Here we assume master.
24-
// Most methods return a ```Result<_, CosmosError>```.
25-
// ```CosmosError``` is an enum union of all the possible underlying
24+
// Most methods return a ```Result<_, azure_cosmos::Error```.
25+
// ```azure_cosmos::Error``` is an enum union of all the possible underlying
2626
// errors, plus Azure specific ones. For example if a REST call returns the
2727
// unexpected result (ie NotFound instead of Ok) we return an Err telling
2828
// you that.

sdk/cosmos/examples/document_00.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
5757

5858
// list_databases will give us the databases available in our account. If there is
5959
// an error (for example, the given key is not valid) you will receive a
60-
// specific CosmosError. In this example we will look for a specific database
60+
// specific azure_cosmos::Error. In this example we will look for a specific database
6161
// so we chain a filter operation.
6262
let db = client
6363
.list_databases()

sdk/cosmos/src/clients/cosmos_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::DatabaseClient;
2+
use crate::headers::*;
23
use crate::operations::*;
34
use crate::resources::permission::AuthorizationToken;
45
use crate::resources::ResourceType;
5-
use crate::{headers::*, CosmosError};
66
use crate::{requests, ReadonlyString};
77

88
use azure_core::pipeline::Pipeline;
@@ -163,15 +163,15 @@ impl CosmosClient {
163163
ctx: Context,
164164
database_name: S,
165165
options: CreateDatabaseOptions,
166-
) -> Result<CreateDatabaseResponse, CosmosError> {
166+
) -> Result<CreateDatabaseResponse, crate::Error> {
167167
let mut request = self.prepare_request2("dbs", http::Method::POST, ResourceType::Databases);
168168
let mut ctx = ctx.clone();
169169
options.decorate_request(&mut request, database_name.as_ref())?;
170170
let response = self
171171
.pipeline()
172172
.send(&mut ctx, &mut request)
173173
.await
174-
.map_err(CosmosError::PolicyError)?;
174+
.map_err(crate::Error::PolicyError)?;
175175

176176
Ok(CreateDatabaseResponse::try_from(response).await?)
177177
}

sdk/cosmos/src/clients/database_client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::*;
22
use crate::operations::*;
33
use crate::requests;
44
use crate::resources::ResourceType;
5-
use crate::CosmosError;
65
use crate::ReadonlyString;
76
use azure_core::pipeline::Pipeline;
87
use azure_core::{Context, HttpClient, Request};
@@ -56,7 +55,7 @@ impl DatabaseClient {
5655
ctx: Context,
5756
collection_name: S,
5857
options: CreateCollectionOptions,
59-
) -> Result<CreateCollectionResponse, CosmosError> {
58+
) -> Result<CreateCollectionResponse, crate::Error> {
6059
let request = self.cosmos_client().prepare_request(
6160
&format!("dbs/{}/colls", self.database_name()),
6261
http::Method::POST,
@@ -70,7 +69,7 @@ impl DatabaseClient {
7069
.pipeline()
7170
.send(&mut ctx, &mut request)
7271
.await
73-
.map_err(CosmosError::PolicyError)?;
72+
.map_err(crate::Error::PolicyError)?;
7473

7574
Ok(CreateCollectionResponse::try_from(response).await?)
7675
}

sdk/cosmos/src/errors.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[allow(missing_docs)]
33
#[non_exhaustive]
44
#[derive(Debug, thiserror::Error)]
5-
pub enum CosmosError {
5+
pub enum Error {
66
#[error(transparent)]
77
AzureCoreError(#[from] azure_core::Error),
88
#[error("Resource quota parsing error: {0}")]
@@ -35,10 +35,6 @@ pub enum CosmosError {
3535
Utf8Error(#[from] std::str::Utf8Error),
3636
#[error("base64 decode error: {0}")]
3737
DecodeError(#[from] base64::DecodeError),
38-
}
39-
40-
#[derive(Debug, thiserror::Error)]
41-
pub enum ConversionToDocumentError {
4238
#[error("Conversion to document failed because at lease one element is raw.")]
43-
RawElementFound,
39+
RawElementError,
4440
}

0 commit comments

Comments
 (0)