Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple warning fixes #477

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/rust/node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl DoraNode {

let node = Self {
id: node_id,
dataflow_id: dataflow_id,
dataflow_id,
node_config: run_config,
control_channel,
clock,
Expand Down
1 change: 1 addition & 0 deletions apis/rust/operator/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(elided_lifetimes_in_paths)] // required for safer-ffi
#![allow(improper_ctypes_definitions)]
#![allow(clippy::missing_safety_doc)]

pub use arrow;
use dora_arrow_convert::{ArrowData, IntoArrow};
Expand Down
6 changes: 2 additions & 4 deletions binaries/cli/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ fn start_coordinator() -> eyre::Result<()> {
let mut cmd =
Command::new(std::env::current_exe().wrap_err("failed to get current executable path")?);
cmd.arg("coordinator");
cmd.spawn()
.wrap_err_with(|| format!("failed to run `dora coordinator`"))?;
cmd.spawn().wrap_err("failed to run `dora coordinator`")?;

println!("started dora coordinator");

Expand All @@ -82,8 +81,7 @@ fn start_daemon() -> eyre::Result<()> {
let mut cmd =
Command::new(std::env::current_exe().wrap_err("failed to get current executable path")?);
cmd.arg("daemon");
cmd.spawn()
.wrap_err_with(|| format!("failed to run `dora daemon`"))?;
cmd.spawn().wrap_err("failed to run `dora daemon`")?;

println!("started dora daemon");

Expand Down
34 changes: 32 additions & 2 deletions binaries/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,27 @@ async fn stop_dataflow_by_uuid(
Ok(())
}

fn format_error(machine: &str, err: &str) -> String {
let mut error = err
.lines()
.fold(format!("- machine `{machine}`:\n"), |mut output, line| {
output.push_str(" ");
output.push_str(line);
output.push('\n');
output
});
error.push('\n');
error
}

fn dataflow_result(
results: &BTreeMap<String, Result<(), String>>,
dataflow_uuid: Uuid,
) -> Result<(), String> {
let mut errors = Vec::new();
for (machine, result) in results {
if let Err(err) = result {
let err: String = err.lines().map(|line| format!(" {line}\n")).collect();
errors.push(format!("- machine `{machine}`:\n{err}\n"));
errors.push(format_error(machine, err));
}
}

Expand Down Expand Up @@ -941,3 +953,21 @@ fn set_up_ctrlc_handler() -> Result<impl Stream<Item = Event>, eyre::ErrReport>

Ok(ReceiverStream::new(ctrlc_rx))
}

#[cfg(test)]
mod test {
#[test]
fn test_format_error() {
let machine = "machine A";
let err = "foo\nbar\nbuzz";

// old method
let old_error = {
#[allow(clippy::format_collect)]
let err: String = err.lines().map(|line| format!(" {line}\n")).collect();
format!("- machine `{machine}`:\n{err}\n")
};
let new_error = super::format_error(machine, err);
assert_eq!(old_error, new_error)
}
}
9 changes: 7 additions & 2 deletions binaries/daemon/src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub async fn spawn_node(
}
};

let dataflow_dir = PathBuf::from(working_dir.join("out").join(dataflow_id.to_string()));
let dataflow_dir: PathBuf = working_dir.join("out").join(dataflow_id.to_string());
if !dataflow_dir.exists() {
std::fs::create_dir_all(&dataflow_dir).context("could not create dataflow_dir")?;
}
Expand Down Expand Up @@ -405,7 +405,12 @@ pub async fn spawn_node(
.write_all(message.as_bytes())
.await
.map_err(|err| error!("Could not log {message} to file due to {err}"));
let formatted: String = message.lines().map(|l| format!(" {l}\n")).collect();
let formatted = message.lines().fold(String::default(), |mut output, line| {
output.push_str(" ");
output.push_str(line);
output.push('\n');
output
});
debug!("{dataflow_id}/{} logged:\n{formatted}", node.id.clone());
// Make sure that all data has been synced to disk.
let _ = file
Expand Down
1 change: 1 addition & 0 deletions binaries/runtime/src/operator/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn run(
if let Event::Reload { .. } = event {
reload = true;
// Reloading method
#[allow(clippy::blocks_in_conditions)]
match Python::with_gil(|py| -> Result<Py<PyAny>> {
// Saving current state
let current_state = operator
Expand Down
4 changes: 2 additions & 2 deletions examples/multiple-daemons/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ async fn main() -> eyre::Result<()> {
dora_coordinator::start(coordinator_bind, ReceiverStream::new(coordinator_events_rx))
.await?;
let coordinator_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), coordinator_port);
let daemon_a = run_daemon(coordinator_addr.to_string(), "A".into());
let daemon_b = run_daemon(coordinator_addr.to_string(), "B".into());
let daemon_a = run_daemon(coordinator_addr.to_string(), "A");
let daemon_b = run_daemon(coordinator_addr.to_string(), "B");

tracing::info!("Spawning coordinator and daemons");
let mut tasks = JoinSet::new();
Expand Down
3 changes: 3 additions & 0 deletions libraries/communication-layer/request-reply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub trait RequestReplyLayer: Send + Sync {
type ReplyData;
type Error;

#[allow(clippy::type_complexity)]
fn listen(
&mut self,
addr: Self::Address,
Expand All @@ -39,6 +40,7 @@ pub trait RequestReplyLayer: Send + Sync {
Self::Error,
>;

#[allow(clippy::type_complexity)]
fn connect(
&mut self,
addr: Self::Address,
Expand All @@ -59,6 +61,7 @@ pub trait ListenConnection: Send + Sync {
type ReplyData;
type Error;

#[allow(clippy::type_complexity)]
fn handle_next(
&mut self,
handler: Box<dyn FnOnce(Self::RequestData) -> Result<Self::ReplyData, Self::Error>>,
Expand Down
2 changes: 1 addition & 1 deletion libraries/core/src/descriptor/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn check_dataflow(dataflow: &Descriptor, working_dir: &Path) -> eyre::Result
OperatorSource::Python(python_source) => {
has_python_operator = true;
let path = &python_source.source;
if source_is_url(&path) {
if source_is_url(path) {
info!("{path} is a URL."); // TODO: Implement url check.
} else if !working_dir.join(path).exists() {
bail!("no Python library at `{path}`");
Expand Down
1 change: 1 addition & 0 deletions libraries/extensions/ros2-bridge/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / CLI Test (ubuntu-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / CLI Test (windows-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / CLI Test (macos-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `std::path::PathBuf`

Check warning on line 1 in libraries/extensions/ros2-bridge/build.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `std::path::PathBuf`

#[cfg(not(feature = "generate-messages"))]
fn main() {}
Expand All @@ -17,6 +17,7 @@
println!("cargo:rustc-env=MESSAGES_PATH={}", target_file.display());
}

#[cfg(feature = "generate-messages")]
fn ament_prefix_paths() -> Vec<PathBuf> {
let ament_prefix_path: String = match std::env::var("AMENT_PREFIX_PATH") {
Ok(path) => path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn bool_literal(s: &str) -> IResult<&str, bool> {
))(s)
}

#[allow(clippy::type_complexity)]
pub fn get_string_literal_parser(
string_type: GenericString,
) -> Box<dyn FnMut(&str) -> IResult<&str, String>> {
Expand Down
8 changes: 5 additions & 3 deletions libraries/extensions/ros2-bridge/msg-gen/src/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ pub fn parse_constant_type(s: &str) -> IResult<&str, ConstantType> {
opt(delimited(char('['), usize_literal, char(']'))),
peek(alt((space1, eof))),
)),
|(value_type, size, _)| match size {
None => value_type.into(),
Some(size) => PrimitiveArray { value_type, size }.into(),
|(value_type, size, _)| {
size.map_or_else(
|| value_type.into(),
|size| PrimitiveArray { value_type, size }.into(),
)
},
)(s)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub enum ConstantType {
impl ConstantType {
pub fn type_tokens(&self) -> impl ToTokens {
match self {
ConstantType::PrimitiveType(t) => {
Self::PrimitiveType(t) => {
let token = t.type_tokens();
quote! { #token }
}
ConstantType::PrimitiveArray(t) => {
Self::PrimitiveArray(t) => {
let token = t.type_tokens();
quote! { #token }
}
Expand All @@ -38,12 +38,12 @@ impl ConstantType {

pub fn value_tokens(&self, values: &[String]) -> impl ToTokens {
match self {
ConstantType::PrimitiveType(t) => {
Self::PrimitiveType(t) => {
assert_eq!(values.len(), 1);
let token = t.value_tokens(&values[0]);
quote! { #token }
}
ConstantType::PrimitiveArray(t) => {
Self::PrimitiveArray(t) => {
assert_eq!(values.len(), t.size);
let tokens = values.iter().map(|v| t.value_type.value_tokens(v));
quote! { [#(#tokens,)*] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Package {
}
}

pub fn token_stream(&self, gen_cxx_bridge: bool) -> impl ToTokens {
pub fn token_stream(&self, _gen_cxx_bridge: bool) -> impl ToTokens {
let name = Ident::new(&self.name, Span::call_site());
let services_block = self.services_block();
let actions_block = self.actions_block();
Expand Down
2 changes: 1 addition & 1 deletion libraries/extensions/ros2-bridge/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Ros2Node {
qos: qos::Ros2QosPolicies,
) -> eyre::Result<Ros2Topic> {
let (namespace_name, message_name) =
match (message_type.split_once("/"), message_type.split_once("::")) {
match (message_type.split_once('/'), message_type.split_once("::")) {
(Some(msg), None) => msg,
(None, Some(msg)) => msg,
_ => eyre::bail!("Expected message type in the format `namespace/message` or `namespace::message`, such as `std_msgs/UInt8` but got: {}", message_type),
Expand Down
1 change: 1 addition & 0 deletions libraries/extensions/ros2-bridge/src/_core/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl U16String {
Self(widestring::U16String::new())
}

#[allow(clippy::should_implement_trait)]
pub fn from_str(arg: &str) -> U16String {
Self(widestring::U16String::from_str(arg))
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/extensions/ros2-bridge/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::missing_safety_doc)]

pub use flume;
pub use futures;
pub use futures_timer;
Expand Down
2 changes: 1 addition & 1 deletion libraries/extensions/telemetry/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ pub fn init_metrics() -> metrics::Result<SdkMeterProvider> {
pub fn init_meter_provider(meter_id: String) -> Result<SdkMeterProvider> {
let meter_provider = init_metrics().context("Could not create opentelemetry meter")?;
let meter = meter_provider.meter(meter_id);
let _ = init_process_observer(meter).context("could not initiale system metrics observer")?;
init_process_observer(meter).context("could not initiale system metrics observer")?;
Ok(meter_provider)
}
2 changes: 2 additions & 0 deletions libraries/message/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Enable serialisation and deserialisation of capnproto messages
//!

#![allow(clippy::missing_safety_doc)]

use arrow_data::ArrayData;
use arrow_schema::DataType;
use eyre::Context;
Expand Down
2 changes: 2 additions & 0 deletions libraries/shared-memory-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::missing_safety_doc)]

use self::channel::ShmemChannel;
use eyre::{eyre, Context};
use serde::{Deserialize, Serialize};
Expand Down
Loading