Skip to content

Commit

Permalink
fixing lint pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zajkowski committed Dec 18, 2024
1 parent ec8056e commit f39009e
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 30 deletions.
6 changes: 5 additions & 1 deletion event_sidecar/src/event_stream_server/sse_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ use casper_event_types::{
sse_data::{EventFilter, SseData},
Filter as SseFilter,
};
use casper_types::{ProtocolVersion, Transaction};
use casper_types::ProtocolVersion;
#[cfg(test)]
use casper_types::Transaction;
use futures::{future, Stream, StreamExt};
use http::StatusCode;
use hyper::Body;
#[cfg(test)]
use serde::Serialize;
#[cfg(test)]
use serde_json::Value;
Expand Down Expand Up @@ -97,6 +100,7 @@ type UrlProps = (
IsLegacyFilter,
);

#[cfg(test)]
#[derive(Serialize)]
#[serde(rename_all = "PascalCase")]
pub(super) struct TransactionAccepted {
Expand Down
4 changes: 2 additions & 2 deletions event_sidecar/src/event_stream_server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,11 @@ async fn fetch_text(
///
/// The expected order is:
/// * data:<JSON-encoded ApiVersion> (note, no ID line follows this first event)
/// then the following three repeated for as many events as are applicable to that stream:
/// then the following three repeated for as many events as are applicable to that stream:
/// * data:<JSON-encoded event>
/// * id:<integer>
/// * empty line
/// then finally, repeated keepalive lines until the server is shut down.
/// then finally, repeated keepalive lines until the server is shut down.
#[allow(clippy::too_many_lines)]
fn parse_response(response_text: String, client_id: &str) -> Vec<ReceivedEvent> {
let mut received_events = Vec::new();
Expand Down
4 changes: 0 additions & 4 deletions event_sidecar/src/testing/simple_sse_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ pub(crate) mod tests {
pub routes: HashMap<Vec<String>, CacheAndData>,
}

#[derive(Debug)]
struct Nope;
impl warp::reject::Reject for Nope {}

type ShutdownCallbacks = Arc<Mutex<Vec<broadcast::Sender<Option<(Option<String>, String)>>>>>;

impl SimpleSseServer {
Expand Down
26 changes: 23 additions & 3 deletions event_sidecar/src/types/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,29 @@ pub enum DatabaseWriteError {
Unhandled(anyhow::Error),
}

impl ToString for DatabaseWriteError {
fn to_string(&self) -> String {
format!("{:?}", self)
impl Display for DatabaseWriteError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
DatabaseWriteError::Serialisation(error) => {
write!(f, "DatabaseWriteError::Serialisation: {}", error)
}
DatabaseWriteError::SqlConstruction(error) => {
write!(f, "DatabaseWriteError::SqlConstruction: {}", error)
}
DatabaseWriteError::UniqueConstraint(unique_constraint_error) => {
write!(
f,
"DatabaseWriteError::UniqueConstraint: table: {}, error: {}",
unique_constraint_error.table, unique_constraint_error.error
)
}
DatabaseWriteError::Database(error) => {
write!(f, "DatabaseWriteError::Database: {}", error)
}
DatabaseWriteError::Unhandled(error) => {
write!(f, "DatabaseWriteError::Unhandled: {}", error)
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions event_sidecar/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ pub mod tests {
let infix_str = infix.as_str();
data.iter().any(|x| x.contains(infix_str))
}

#[allow(dead_code)]
pub struct MockNodeTestProperties {
pub testing_config: TestingConfig,
pub temp_storage_dir: TempDir,
Expand Down
1 change: 1 addition & 0 deletions json_rpc/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Request {
/// * `allow_unknown_fields` is `false` and extra fields exist
///
/// Returns a `Rejection` if the "id" field is `None`.
#[allow(clippy::result_large_err)]
pub(super) fn new(
mut request: Map<String, Value>,
allow_unknown_fields: bool,
Expand Down
1 change: 1 addition & 0 deletions json_rpc/src/request/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Params {
}

impl Params {
#[allow(clippy::result_large_err)]
pub(super) fn try_from(request_id: &Value, params: Value) -> Result<Self, ErrorOrRejection> {
let err_invalid_request = |additional_info: &str| {
let error = Error::new(ReservedErrorCode::InvalidRequest, additional_info);
Expand Down
1 change: 0 additions & 1 deletion listener/src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ impl DefaultConnectionManagerBuilder {
impl DefaultConnectionManager {
/// Start handling traffic from nodes endpoint. This function is blocking, it will return a
/// ConnectionManagerError result if something went wrong while processing.
async fn connect(
&mut self,
) -> Result<Pin<Box<dyn Stream<Item = EventResult> + Send + 'static>>, ConnectionManagerError>
Expand Down
13 changes: 5 additions & 8 deletions listener/src/sse_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use eventsource_stream::{Event, EventStream, EventStreamError, Eventsource};
use futures::StreamExt;
use reqwest::Client;
use std::pin::Pin;
use std::{fmt::Debug, sync::Arc, time::Duration};
use std::{fmt::Debug, time::Duration};
use tokio::select;
use tokio_stream::Stream;
use tracing::debug;
Expand All @@ -17,7 +17,7 @@ use url::Url;
#[derive(Clone, Debug)]
pub enum SseDataStreamingError {
NoDataTimeout(),
ConnectionError(Arc<Error>),
ConnectionError(),
}

pub type EventResult = Result<Event, EventStreamError<SseDataStreamingError>>;
Expand Down Expand Up @@ -84,8 +84,8 @@ impl SseConnection {
monitor.tick().await;
yield Ok(bytes);
},
Err(err) => {
yield Err(SseDataStreamingError::ConnectionError(Arc::new(Error::from(err))));
Err(_) => {
yield Err(SseDataStreamingError::ConnectionError());
break;
}
}
Expand Down Expand Up @@ -177,7 +177,6 @@ pub mod tests {
use std::{
convert::Infallible,
pin::Pin,
sync::Arc,
time::{Duration, Instant},
};
use tokio::sync::mpsc::channel;
Expand Down Expand Up @@ -225,9 +224,7 @@ pub mod tests {
}

pub fn build_failing_on_message() -> Self {
let e = SseDataStreamingError::ConnectionError(Arc::new(Error::msg(
"Some error on message",
)));
let e = SseDataStreamingError::ConnectionError();
MockSseConnection {
data: vec![],
failure_on_connection: None,
Expand Down
10 changes: 2 additions & 8 deletions listener/src/version_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,11 @@ fn try_resolve_version(raw_response: &Value) -> Result<ProtocolVersion, Error> {
let raw = build_version_value
.as_str()
.context("build_version_value should be a string")
.map_err(|e| {
count_error("version_value_not_a_string");
e
})?
.inspect_err(|_| count_error("version_value_not_a_string"))?
.split('-')
.next()
.context("splitting build_version_value should always return at least one slice")
.map_err(|e| {
count_error("incomprehensible_build_version_form");
e
})?;
.inspect_err(|_| count_error("incomprehensible_build_version_form"))?;
ProtocolVersion::from_str(raw).map_err(|error| {
count_error("failed_parsing_protocol_version");
anyhow!("failed parsing build version from '{}': {}", raw, error)
Expand Down
2 changes: 1 addition & 1 deletion rpc_sidecar/src/node_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ where
#[derive(Clone, Copy, Debug)]
pub(crate) struct ErrFormatter<'a, T>(pub &'a T);

impl<'a, T> Display for ErrFormatter<'a, T>
impl<T> Display for ErrFormatter<'_, T>
where
T: std::error::Error,
{
Expand Down
4 changes: 2 additions & 2 deletions sidecar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use config::{SidecarConfig, SidecarConfigTarget};
use run::run;
use std::{
env, fmt, io,
panic::{self, PanicInfo},
panic::{self, PanicHookInfo},
process::{self, ExitCode},
};
#[cfg(not(target_env = "msvc"))]
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn read_config(config_path: &str) -> Result<SidecarConfigTarget, Error> {
toml::from_str(&toml_content).context("Error parsing config into TOML format")
}

fn panic_hook(info: &PanicInfo) {
fn panic_hook(info: &PanicHookInfo) {
let backtrace = Backtrace::new();

eprintln!("{:?}", backtrace);
Expand Down

0 comments on commit f39009e

Please sign in to comment.