build(deps): bump error-stack from version 0.3.1 to 0.4.1 (#4188)

This commit is contained in:
Sanchith Hegde
2024-04-01 12:31:17 +05:30
committed by GitHub
parent cb2000b088
commit ea730d4ffc
286 changed files with 1361 additions and 2397 deletions

View File

@ -1,7 +1,7 @@
//! Utilities for cryptographic algorithms
use std::ops::Deref;
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use masking::{ExposeInterface, Secret};
use md5;
use ring::{
@ -248,18 +248,15 @@ impl EncodeMessage for GcmAes256 {
secret: &[u8],
msg: &[u8],
) -> CustomResult<Vec<u8>, errors::CryptoError> {
let nonce_sequence = NonceSequence::new()
.into_report()
.change_context(errors::CryptoError::EncodingFailed)?;
let nonce_sequence =
NonceSequence::new().change_context(errors::CryptoError::EncodingFailed)?;
let current_nonce = nonce_sequence.current();
let key = UnboundKey::new(&aead::AES_256_GCM, secret)
.into_report()
.change_context(errors::CryptoError::EncodingFailed)?;
let mut key = SealingKey::new(key, nonce_sequence);
let mut in_out = msg.to_vec();
key.seal_in_place_append_tag(aead::Aad::empty(), &mut in_out)
.into_report()
.change_context(errors::CryptoError::EncodingFailed)?;
in_out.splice(0..0, current_nonce);
@ -275,17 +272,15 @@ impl DecodeMessage for GcmAes256 {
) -> CustomResult<Vec<u8>, errors::CryptoError> {
let msg = msg.expose();
let key = UnboundKey::new(&aead::AES_256_GCM, secret)
.into_report()
.change_context(errors::CryptoError::DecodingFailed)?;
let nonce_sequence = NonceSequence::from_bytes(
msg.get(..ring::aead::NONCE_LEN)
.ok_or(errors::CryptoError::DecodingFailed)
.into_report()
.attach_printable("Failed to read the nonce form the encrypted ciphertext")?
.try_into()
.into_report()
.change_context(errors::CryptoError::DecodingFailed)?,
<[u8; ring::aead::NONCE_LEN]>::try_from(
msg.get(..ring::aead::NONCE_LEN)
.ok_or(errors::CryptoError::DecodingFailed)
.attach_printable("Failed to read the nonce form the encrypted ciphertext")?,
)
.change_context(errors::CryptoError::DecodingFailed)?,
);
let mut key = OpeningKey::new(key, nonce_sequence);
@ -294,7 +289,6 @@ impl DecodeMessage for GcmAes256 {
let result = key
.open_within(aead::Aad::empty(), output, ring::aead::NONCE_LEN..)
.into_report()
.change_context(errors::CryptoError::DecodingFailed)?;
Ok(result.to_vec())
@ -329,7 +323,6 @@ impl VerifySignature for Sha512 {
msg: &[u8],
) -> CustomResult<bool, errors::CryptoError> {
let msg_str = std::str::from_utf8(msg)
.into_report()
.change_context(errors::CryptoError::EncodingFailed)?
.to_owned();
let hashed_digest = hex::encode(

View File

@ -3,7 +3,7 @@
//! & inbuilt datatypes.
//!
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use masking::{ExposeInterface, PeekInterface, Secret, Strategy};
use quick_xml::de;
use serde::{Deserialize, Serialize};
@ -101,7 +101,6 @@ where
serde_json::to_string(
&P::try_from(self).change_context(errors::ParsingError::UnknownError)?,
)
.into_report()
.change_context(errors::ParsingError::EncodeError("string"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a request"))
}
@ -115,7 +114,6 @@ where
serde_urlencoded::to_string(
&P::try_from(self).change_context(errors::ParsingError::UnknownError)?,
)
.into_report()
.change_context(errors::ParsingError::EncodeError("url-encoded"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a request"))
}
@ -126,7 +124,6 @@ where
Self: Serialize,
{
serde_urlencoded::to_string(self)
.into_report()
.change_context(errors::ParsingError::EncodeError("url-encoded"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a request"))
}
@ -136,7 +133,6 @@ where
Self: Serialize,
{
serde_json::to_string(self)
.into_report()
.change_context(errors::ParsingError::EncodeError("json"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a request"))
}
@ -146,7 +142,6 @@ where
Self: Serialize,
{
quick_xml::se::to_string(self)
.into_report()
.change_context(errors::ParsingError::EncodeError("xml"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a request"))
}
@ -156,7 +151,6 @@ where
Self: Serialize,
{
serde_json::to_value(self)
.into_report()
.change_context(errors::ParsingError::EncodeError("json-value"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a value"))
}
@ -166,7 +160,6 @@ where
Self: Serialize,
{
serde_json::to_vec(self)
.into_report()
.change_context(errors::ParsingError::EncodeError("byte-vec"))
.attach_printable_lazy(|| format!("Unable to convert {self:?} to a value"))
}
@ -198,7 +191,6 @@ impl BytesExt for bytes::Bytes {
use bytes::Buf;
serde_json::from_slice::<T>(self.chunk())
.into_report()
.change_context(errors::ParsingError::StructParseFailure(type_name))
.attach_printable_lazy(|| {
let variable_type = std::any::type_name::<T>();
@ -232,7 +224,6 @@ impl ByteSliceExt for [u8] {
T: Deserialize<'de>,
{
serde_json::from_slice(self)
.into_report()
.change_context(errors::ParsingError::StructParseFailure(type_name))
.attach_printable_lazy(|| format!("Unable to parse {type_name} from &[u8] {:?}", &self))
}
@ -260,7 +251,6 @@ impl ValueExt for serde_json::Value {
&self
);
serde_json::from_value::<T>(self)
.into_report()
.change_context(errors::ParsingError::StructParseFailure(type_name))
.attach_printable_lazy(|| debug)
}
@ -318,7 +308,6 @@ impl<T> StringExt<T> for String {
<T as std::str::FromStr>::Err: std::error::Error + Send + Sync + 'static,
{
T::from_str(&self)
.into_report()
.change_context(errors::ParsingError::EnumParseFailure(enum_name))
.attach_printable_lazy(|| format!("Invalid enum variant {self:?} for enum {enum_name}"))
}
@ -331,7 +320,6 @@ impl<T> StringExt<T> for String {
T: Deserialize<'de>,
{
serde_json::from_str::<T>(self)
.into_report()
.change_context(errors::ParsingError::StructParseFailure(type_name))
.attach_printable_lazy(|| {
format!("Unable to parse {type_name} from string {:?}", &self)
@ -543,7 +531,6 @@ where
Err(errors::ValidationError::MissingRequiredField {
field_name: field_name.to_string(),
})
.into_report()
.attach_printable(format!("Missing required field {field_name} in {self:?}"))
})
}
@ -559,7 +546,6 @@ where
None => Err(errors::ValidationError::MissingRequiredField {
field_name: field_name.to_string(),
})
.into_report()
.attach_printable(format!("Missing required field {field_name} in {self:?}")),
}
}
@ -576,7 +562,6 @@ where
.change_context(errors::ParsingError::UnknownError)?;
E::from_str(value.as_ref())
.into_report()
.change_context(errors::ParsingError::UnknownError)
.attach_printable_lazy(|| format!("Invalid {{ {enum_name}: {value:?} }} "))
}

View File

@ -10,7 +10,7 @@ use diesel::{
serialize::{Output, ToSql},
sql_types, AsExpression,
};
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use masking::{ExposeInterface, Secret, Strategy, WithType};
#[cfg(feature = "logs")]
use router_env::logger;
@ -308,8 +308,8 @@ impl FromStr for Email {
}
Err(_) => Err(ValidationError::InvalidValue {
message: "Invalid email address format".into(),
})
.into_report(),
}
.into()),
}
}
}

View File

@ -8,7 +8,7 @@ use diesel::{
sql_types::Jsonb,
AsExpression, FromSqlRow,
};
use error_stack::{IntoReport, ResultExt};
use error_stack::{report, ResultExt};
use semver::Version;
use serde::{de::Visitor, Deserialize, Deserializer};
@ -37,12 +37,11 @@ impl<const PRECISION: u8> Percentage<PRECISION> {
if Self::is_valid_string_value(&value)? {
Ok(Self {
percentage: value
.parse()
.into_report()
.parse::<f32>()
.change_context(PercentageError::InvalidPercentageValue)?,
})
} else {
Err(PercentageError::InvalidPercentageValue.into())
Err(report!(PercentageError::InvalidPercentageValue))
.attach_printable(get_invalid_percentage_error_message(PRECISION))
}
}
@ -57,11 +56,10 @@ impl<const PRECISION: u8> Percentage<PRECISION> {
let max_amount = i64::MAX / 10000;
if amount > max_amount {
// value gets rounded off after i64::MAX/10000
Err(PercentageError::UnableToApplyPercentage {
Err(report!(PercentageError::UnableToApplyPercentage {
percentage: self.percentage,
amount,
}
.into())
}))
.attach_printable(format!(
"Cannot calculate percentage for amount greater than {}",
max_amount
@ -78,8 +76,7 @@ impl<const PRECISION: u8> Percentage<PRECISION> {
}
fn is_valid_float_string(value: &str) -> CustomResult<f32, PercentageError> {
value
.parse()
.into_report()
.parse::<f32>()
.change_context(PercentageError::InvalidPercentageValue)
}
fn is_valid_range(value: f32) -> bool {
@ -182,7 +179,7 @@ impl FromStr for SemanticVersion {
type Err = error_stack::Report<ParsingError>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(Version::from_str(s).into_report().change_context(
Ok(Self(Version::from_str(s).change_context(
ParsingError::StructParseFailure("SemanticVersion"),
)?))
}