Skip to content

Commit

Permalink
feat(rad): add new RadonErrors::BufferIsNotValue
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Oct 26, 2023
1 parent 184f768 commit cd4641c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions data_structures/src/radon_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum RadonErrors {
HTTPError = 0x30,
/// Al least one of the sources could not be retrieved, timeout reached.
RetrieveTimeout = 0x31,
/// Value cannot be extracted from binary buffer
BufferIsNotValue = 0x32,
// Math errors
/// Math operator caused an underflow.
Underflow = 0x40,
Expand Down
5 changes: 5 additions & 0 deletions rad/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ impl RadError {
}

Ok(RadonError::new(match kind {
RadonErrors::BufferIsNotValue => {
let (description,) = deserialize_args(error_args)?;
RadError::BufferIsNotValue { description }
}
RadonErrors::RequestTooManySources => RadError::RequestTooManySources,
RadonErrors::ScriptTooManyCalls => RadError::ScriptTooManyCalls,
RadonErrors::Overflow => RadError::Overflow,
Expand Down Expand Up @@ -574,6 +578,7 @@ impl RadError {
pub fn try_into_error_code(&self) -> Result<RadonErrors, RadError> {
Ok(match self {
RadError::Unknown => RadonErrors::Unknown,
RadError::BufferIsNotValue { .. } => RadonErrors::BufferIsNotValue,
RadError::SourceScriptNotCBOR => RadonErrors::SourceScriptNotCBOR,
RadError::SourceScriptNotArray => RadonErrors::SourceScriptNotArray,
RadError::SourceScriptNotRADON => RadonErrors::SourceScriptNotRADON,
Expand Down
13 changes: 5 additions & 8 deletions rad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use witnet_data_structures::{
RADAggregate, RADRequest, RADRetrieve, RADTally, RADType,
},
radon_report::{RadonReport, ReportContext, RetrievalMetadata, Stage, TallyMetaData},
witnessing::WitnessingConfig, radon_error::RadonError,
witnessing::WitnessingConfig,
};
use witnet_net::client::http::WitnetHttpClient;
pub use witnet_net::Uri;
Expand Down Expand Up @@ -298,12 +298,9 @@ async fn http_response(
let mut response_bytes = Vec::<u8>::default();
match retrieve.kind {
RADType::HttpHead => {
response = RadonTypes::RadonError(
RadonError::try_from(RadError::BufferIsNotValue {
description: String::from("Unsupported binary streams from HTTP/HEAD sources")
})
.unwrap()
);
return Err(RadError::BufferIsNotValue {
description: String::from("Unsupported binary streams from HTTP/HEAD sources")
});
}
_ => {
// todo: before reading the response buffer, an error should be thrown if it was too big
Expand All @@ -312,9 +309,9 @@ async fn http_response(
message: x.to_string(),
}
})?;
response = RadonTypes::from(RadonBytes::from(response_bytes));
}
}
response = RadonTypes::from(RadonBytes::from(response_bytes));
} else {
// response is a string
let mut response_string = String::default();
Expand Down

0 comments on commit cd4641c

Please sign in to comment.