This commit is contained in:
AsafMah 2022-06-07 16:08:16 +03:00
Родитель 2064fa2363
Коммит 3b96e4fc5d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: AD0D1680EEE7A4FF
4 изменённых файлов: 32 добавлений и 39 удалений

Просмотреть файл

@ -13,11 +13,8 @@ pub enum Error {
ExternalError(String),
/// Error raised when an invalid argument / option is provided.
#[error("Invalid argument {source}")]
InvalidArgumentError {
#[source]
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("Invalid argument {0}")]
InvalidArgumentError(#[from] InvalidArgumentError),
/// Error raised when specific functionality is not (yet) implemented
#[error("Feature not implemented")]
@ -29,25 +26,19 @@ pub enum Error {
/// Error occurring within core azure crates
#[error(transparent)]
AzureError(#[from] azure_core::Error),
AzureError(#[from] azure_core::error::Error),
/// Errors raised when parsing connection information
#[error("Configuration error: {0}")]
ConfigurationError(#[from] crate::connection_string::ConnectionStringError),
}
#[derive(thiserror::Error, Debug)]
pub enum InvalidArgumentError {
#[error(transparent)]
InvalidUri(#[from] InvalidUri),
#[error("{0} is not a valid duration")]
InvalidDuration(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<azure_core::error::Error> for Error {
fn from(err: azure_core::error::Error) -> Self {
Self::AzureError(err.into())
}
}
impl From<InvalidUri> for Error {
fn from(error: InvalidUri) -> Self {
Self::InvalidArgumentError {
source: Box::new(error),
}
}
}

Просмотреть файл

@ -1,4 +1,5 @@
use crate::client::KustoClient;
use crate::error::InvalidArgumentError;
use crate::models::{QueryBody, RequestProperties, TableV1};
use crate::request_options::RequestOptions;
use async_convert::TryFrom;
@ -61,9 +62,10 @@ impl ManagementQueryBuilder {
Box::pin(async move {
let url = this.client.management_url();
let mut request = this
.client
.prepare_request(url.parse()?, http::Method::POST);
let mut request = this.client.prepare_request(
url.parse().map_err(InvalidArgumentError::InvalidUri)?,
http::Method::POST,
);
if let Some(request_id) = &this.client_request_id {
request.insert_headers(request_id);

Просмотреть файл

@ -1,6 +1,7 @@
#[cfg(feature = "arrow")]
use crate::arrow::convert_table;
use crate::client::KustoClient;
use crate::error::InvalidArgumentError;
use crate::models::{
DataSetCompletion, DataSetHeader, DataTable, QueryBody, RequestProperties, TableKind,
};
@ -67,9 +68,10 @@ impl ExecuteQueryBuilder {
Box::pin(async move {
let url = this.client.query_url();
let mut request = this
.client
.prepare_request(url.parse()?, http::Method::POST);
let mut request = this.client.prepare_request(
url.parse().map_err(InvalidArgumentError::InvalidUri)?,
http::Method::POST,
);
if let Some(request_id) = &this.client_request_id {
request.insert_headers(request_id);

Просмотреть файл

@ -7,7 +7,7 @@ use std::ops::Deref;
use std::str::FromStr;
use time::{Duration, OffsetDateTime};
use crate::error::Error;
use crate::error::{Error, InvalidArgumentError};
use time::format_description::well_known::Rfc3339;
#[derive(PartialEq, Copy, Clone, DeserializeFromStr, SerializeDisplay)]
@ -55,16 +55,16 @@ impl Deref for KustoDateTime {
}
#[derive(PartialEq, Copy, Clone, DeserializeFromStr, SerializeDisplay)]
pub struct KustoDuration(pub time::Duration);
pub struct KustoDuration(pub Duration);
impl From<time::Duration> for KustoDuration {
impl From<Duration> for KustoDuration {
fn from(duration: Duration) -> Self {
KustoDuration(duration)
}
}
impl Deref for KustoDuration {
type Target = time::Duration;
type Target = Duration;
fn deref(&self) -> &Self::Target {
&self.0
@ -79,7 +79,7 @@ fn parse_regex_segment(captures: &Captures, name: &str) -> i64 {
}
impl FromStr for KustoDuration {
type Err = crate::error::Error;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
lazy_static! {
@ -96,16 +96,14 @@ impl FromStr for KustoDuration {
let seconds = parse_regex_segment(&captures, "seconds");
let nanos = parse_regex_segment(&captures, "nanos");
let duration = neg
* (time::Duration::days(days)
+ time::Duration::hours(hours)
+ time::Duration::minutes(minutes)
+ time::Duration::seconds(seconds)
+ time::Duration::nanoseconds(nanos * 100)); // Ticks
* (Duration::days(days)
+ Duration::hours(hours)
+ Duration::minutes(minutes)
+ Duration::seconds(seconds)
+ Duration::nanoseconds(nanos * 100)); // Ticks
Ok(KustoDuration(duration))
} else {
Err(Error::InvalidArgumentError {
source: format!("{} is not a valid duration", s).into(),
})
Err(InvalidArgumentError::InvalidDuration(s.to_string()).into())
}
}
}