Skip to content

Commit 4ab01ea

Browse files
committed
Fix clippy warnings
1 parent d55aba9 commit 4ab01ea

File tree

23 files changed

+58
-68
lines changed

23 files changed

+58
-68
lines changed

quickwit/quickwit-actors/src/registry.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ impl ActorRegistry {
166166

167167
pub fn get_one<A: Actor>(&self) -> Option<Mailbox<A>> {
168168
let mut lock = self.actors.write().unwrap();
169-
let opt = get_iter::<A>(&mut lock).next();
170-
opt
169+
get_iter::<A>(&mut lock).next()
171170
}
172171

173172
fn gc(&self) {

quickwit/quickwit-cli/src/index.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,12 @@ impl IndexStats {
785785
tables.push(size_stats_table);
786786
}
787787

788-
let table = Table::builder(tables.into_iter().map(|table| table.to_string()))
788+
Table::builder(tables.into_iter().map(|table| table.to_string()))
789789
.build()
790790
.with(Modify::new(Segment::all()).with(Alignment::center_vertical()))
791791
.with(Disable::row(FirstRow))
792792
.with(Style::empty())
793-
.to_string();
794-
795-
table
793+
.to_string()
796794
}
797795
}
798796

quickwit/quickwit-common/src/io.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ impl IoControls {
125125

126126
pub fn check_if_alive(&self) -> io::Result<ProtectedZoneGuard> {
127127
if self.kill_switch.is_dead() {
128-
return Err(io::Error::new(
129-
io::ErrorKind::Other,
130-
"Directory kill switch was activated.",
131-
));
128+
return Err(io::Error::other("directory kill switch was activated"));
132129
}
133130
let guard = self.progress.protect_zone();
134131
Ok(guard)

quickwit/quickwit-common/src/net.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,9 @@ fn _get_hostname(hostname: OsString) -> io::Result<String> {
327327
if is_valid_hostname(&hostname_lossy) {
328328
Ok(hostname_lossy.to_string())
329329
} else {
330-
Err(io::Error::new(
331-
io::ErrorKind::Other,
332-
format!("invalid hostname: `{hostname_lossy}`"),
333-
))
330+
Err(io::Error::other(format!(
331+
"invalid hostname: `{hostname_lossy}`"
332+
)))
334333
}
335334
}
336335

quickwit/quickwit-directories/src/bundle_directory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl BundleDirectory {
113113
pub fn open_split(split_file: FileSlice) -> io::Result<BundleDirectory> {
114114
// First we remove the hotcache from our file slice.
115115
let (body_and_bundle_metadata, _hot_cache) = split_footer(split_file)?;
116-
BundleDirectory::open_bundle(body_and_bundle_metadata)
117-
.map_err(|anyhow_err| io::Error::new(io::ErrorKind::Other, anyhow_err))
116+
BundleDirectory::open_bundle(body_and_bundle_metadata).map_err(io::Error::other)
118117
}
119118

120119
/// Opens a BundleDirectory, given a file containing the bundle data.

quickwit/quickwit-directories/src/storage_directory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ impl StorageDirectory {
111111
}
112112

113113
fn unsupported_operation(path: &Path) -> io::Error {
114-
let msg = "Unsupported operation. StorageDirectory only supports async reads";
115-
error!(path=?path, msg);
116-
io::Error::new(io::ErrorKind::Other, format!("{msg}: {path:?}"))
114+
let error = "unsupported operation: `StorageDirectory` only supports async reads";
115+
error!(error, ?path);
116+
io::Error::other(format!("{error}: {}", path.display()))
117117
}
118118

119119
impl Directory for StorageDirectory {

quickwit/quickwit-indexing/src/source/file_source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::source::{Source, SourceContext, SourceRuntime, TypedSourceFactory};
3030

3131
enum FileSourceState {
3232
#[cfg(feature = "queue-sources")]
33-
Notification(QueueCoordinator),
33+
Notification(Box<QueueCoordinator>),
3434
Filepath {
3535
batch_reader: ObjectUriBatchReader,
3636
num_bytes_processed: u64,
@@ -180,7 +180,7 @@ impl TypedSourceFactory for FileSourceFactory {
180180
)) => {
181181
let coordinator =
182182
QueueCoordinator::try_from_sqs_config(sqs_config, source_runtime).await?;
183-
FileSourceState::Notification(coordinator)
183+
FileSourceState::Notification(Box::new(coordinator))
184184
}
185185
#[cfg(not(feature = "sqs"))]
186186
FileSourceParams::Notifications(quickwit_config::FileSourceNotification::Sqs(_)) => {

quickwit/quickwit-indexing/src/source/kafka_source.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,11 +785,10 @@ mod kafka_broker_tests {
785785
}
786786

787787
fn create_admin_client() -> AdminClient<DefaultClientContext> {
788-
let admin_client = ClientConfig::new()
788+
ClientConfig::new()
789789
.set("bootstrap.servers", "localhost:9092")
790790
.create()
791-
.unwrap();
792-
admin_client
791+
.unwrap()
793792
}
794793

795794
async fn create_topic(

quickwit/quickwit-ingest/src/mrecordlog_async.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ impl MultiRecordLogAsync {
5959
.await
6060
.map_err(|join_err| {
6161
error!(error=?join_err, "failed to load WAL");
62-
ReadRecordError::IoError(io::Error::new(
63-
io::ErrorKind::Other,
64-
"loading wal from directory failed",
65-
))
62+
ReadRecordError::IoError(io::Error::other("loading wal from directory failed"))
6663
})??;
6764
Ok(Self {
6865
mrecordlog_opt: Some(mrecordlog),

quickwit/quickwit-jaeger/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ fn build_aggregations_query(num_traces: usize) -> String {
756756
query
757757
}
758758

759+
#[allow(clippy::result_large_err)]
759760
fn qw_span_to_jaeger_span(qw_span_json: &str) -> Result<JaegerSpan, Status> {
760761
let mut qw_span: QwSpan = json_deserialize(qw_span_json, "span")?;
761762

@@ -1027,6 +1028,7 @@ fn otlp_attributes_to_jaeger_tags_inner(
10271028

10281029
/// Converts OpenTelemetry links to Jaeger span references.
10291030
/// <https://opentelemetry.io/docs/specs/otel/trace/sdk_exporters/jaeger/#links>
1031+
#[allow(clippy::result_large_err)]
10301032
fn otlp_links_to_jaeger_references(
10311033
trace_id: &TraceId,
10321034
parent_span_id_opt: Option<SpanId>,
@@ -1058,6 +1060,7 @@ fn otlp_links_to_jaeger_references(
10581060
Ok(references)
10591061
}
10601062

1063+
#[allow(clippy::result_large_err)]
10611064
fn qw_event_to_jaeger_log(event: QwEvent) -> Result<JaegerLog, Status> {
10621065
let timestamp = to_well_known_timestamp(event.event_timestamp_nanos);
10631066
// "OpenTelemetry Event’s name field should be added to Jaeger Log’s fields map as follows: name
@@ -1087,6 +1090,7 @@ fn qw_event_to_jaeger_log(event: QwEvent) -> Result<JaegerLog, Status> {
10871090
Ok(log)
10881091
}
10891092

1093+
#[allow(clippy::result_large_err)]
10901094
fn collect_trace_ids(
10911095
trace_ids_postcard: &[u8],
10921096
) -> Result<(Vec<TraceId>, TimeIntervalSecs), Status> {
@@ -1107,6 +1111,7 @@ fn collect_trace_ids(
11071111
Ok((trace_ids, start..=end))
11081112
}
11091113

1114+
#[allow(clippy::result_large_err)]
11101115
fn json_deserialize<'a, T>(json: &'a str, label: &'static str) -> Result<T, Status>
11111116
where T: Deserialize<'a> {
11121117
match serde_json::from_str(json) {
@@ -1120,6 +1125,7 @@ where T: Deserialize<'a> {
11201125
}
11211126
}
11221127

1128+
#[allow(clippy::result_large_err)]
11231129
fn postcard_deserialize<'a, T>(json: &'a [u8], label: &'static str) -> Result<T, Status>
11241130
where T: Deserialize<'a> {
11251131
match postcard::from_bytes(json) {

quickwit/quickwit-metastore/src/tests/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ async fn create_channel(client: tokio::io::DuplexStream) -> anyhow::Result<Chann
8888
let channel = Endpoint::try_from("http://test.server")?
8989
.connect_with_connector(tower::service_fn(move |_: Uri| {
9090
let client = client.take();
91-
async move {
92-
client.ok_or_else(|| {
93-
std::io::Error::new(std::io::ErrorKind::Other, "client already taken")
94-
})
95-
}
91+
async move { client.ok_or_else(|| std::io::Error::other("client already taken")) }
9692
}))
9793
.await?;
9894
Ok(channel)

quickwit/quickwit-opentelemetry/src/otlp/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ fn is_zero(count: &u32) -> bool {
177177
*count == 0
178178
}
179179

180+
#[allow(clippy::result_large_err)]
180181
pub fn extract_otel_traces_index_id_patterns_from_metadata(
181182
metadata: &tonic::metadata::MetadataMap,
182183
) -> Result<Vec<String>, Status> {
@@ -205,6 +206,7 @@ pub fn extract_otel_traces_index_id_patterns_from_metadata(
205206
Ok(index_id_patterns)
206207
}
207208

209+
#[allow(clippy::result_large_err)]
208210
pub(crate) fn extract_otel_index_id_from_metadata(
209211
metadata: &tonic::metadata::MetadataMap,
210212
otel_signal: OtelSignal,

quickwit/quickwit-proto/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ fn decode_error<E: DeserializeOwned>(header_value: &BinaryMetadataValue) -> anyh
183183
Ok(service_error)
184184
}
185185

186+
#[allow(clippy::result_large_err)]
186187
pub fn convert_to_grpc_result<T, E: GrpcServiceError>(
187188
result: Result<T, E>,
188189
) -> tonic::Result<tonic::Response<T>> {

quickwit/quickwit-proto/src/search/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub fn deserialize_split_fields<R: Read>(mut reader: R) -> io::Result<ListFields
263263
}
264264

265265
/// Reads the Split fields from a stream of bytes
266+
#[allow(clippy::unbuffered_bytes)]
266267
fn read_split_fields_from_zstd<R: Read>(reader: R) -> io::Result<ListFields> {
267268
let all_bytes: Vec<_> = reader.bytes().collect::<io::Result<_>>()?;
268269
let serialized_list_fields: ListFields = prost::Message::decode(&all_bytes[..])?;

quickwit/quickwit-serve/src/elasticsearch_api/bulk_v2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub(crate) async fn elastic_bulk_ingest_v2(
166166
)
167167
}
168168

169+
#[allow(clippy::result_large_err)]
169170
fn make_elastic_bulk_response_v2(
170171
ingest_response_v2: IngestResponseV2,
171172
mut per_subrequest_doc_handles: HashMap<u32, Vec<DocHandle>>,
@@ -348,6 +349,7 @@ fn make_elastic_bulk_response_v2(
348349
Ok(bulk_response)
349350
}
350351

352+
#[allow(clippy::result_large_err)]
351353
fn remove_doc_handles(
352354
per_subrequest_doc_handles: &mut HashMap<u32, Vec<DocHandle>>,
353355
subrequest_id: u32,

quickwit/quickwit-serve/src/elasticsearch_api/model/cat_indices.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct CatIndexQueryParams {
5353
pub v: Option<bool>,
5454
}
5555
impl CatIndexQueryParams {
56+
#[allow(clippy::result_large_err)]
5657
pub fn validate(&self) -> Result<(), ElasticsearchError> {
5758
if let Some(format) = &self.format {
5859
if format.to_lowercase() != "json" {

quickwit/quickwit-serve/src/elasticsearch_api/model/field_capability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub fn convert_to_es_field_capabilities_response(
179179
FieldCapabilityResponse { indices, fields }
180180
}
181181

182+
#[allow(clippy::result_large_err)]
182183
pub fn build_list_field_request_for_es_api(
183184
index_id_patterns: Vec<String>,
184185
search_params: FieldCapabilityQueryParams,

quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub fn es_compat_scroll_handler(
302302
.boxed()
303303
}
304304

305+
#[allow(clippy::result_large_err)]
305306
fn build_request_for_es_api(
306307
index_id_patterns: Vec<String>,
307308
search_params: SearchQueryParams,
@@ -418,6 +419,7 @@ fn is_doc_field(field: &quickwit_proto::search::SortField) -> bool {
418419
field.field_name == "_shard_doc" || field.field_name == "_doc"
419420
}
420421

422+
#[allow(clippy::result_large_err)]
421423
fn partial_hit_from_search_after_param(
422424
search_after: Vec<serde_json::Value>,
423425
sort_order: &[quickwit_proto::search::SortField],
@@ -991,6 +993,7 @@ fn convert_to_es_stats_response(
991993
ElasticsearchStatsResponse { _all, indices }
992994
}
993995

996+
#[allow(clippy::result_large_err)]
994997
fn convert_to_es_search_response(
995998
resp: SearchResponse,
996999
append_shard_doc: bool,

quickwit/quickwit-serve/src/rest.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,33 +494,34 @@ mod tls {
494494
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
495495
use tokio_rustls::rustls::ServerConfig;
496496

497-
fn error(err: String) -> io::Error {
498-
io::Error::new(io::ErrorKind::Other, err)
497+
fn io_error(error: String) -> io::Error {
498+
io::Error::other(error)
499499
}
500500

501501
// Load public certificate from file.
502502
fn load_certs(filename: &str) -> io::Result<Vec<rustls::Certificate>> {
503503
// Open certificate file.
504-
let certfile =
505-
fs::read(filename).map_err(|e| error(format!("failed to open {}: {}", filename, e)))?;
504+
let certfile = fs::read(filename)
505+
.map_err(|error| io_error(format!("failed to open {filename}: {error}")))?;
506506

507507
// Load and return certificate.
508508
let certs = rustls_pemfile::certs(&mut certfile.as_ref())
509-
.map_err(|_| error("failed to load certificate".into()))?;
509+
.map_err(|_| io_error("failed to load certificate".to_string()))?;
510510
Ok(certs.into_iter().map(rustls::Certificate).collect())
511511
}
512512

513513
// Load private key from file.
514514
fn load_private_key(filename: &str) -> io::Result<rustls::PrivateKey> {
515515
// Open keyfile.
516-
let keyfile =
517-
fs::read(filename).map_err(|e| error(format!("failed to open {}: {}", filename, e)))?;
516+
let keyfile = fs::read(filename)
517+
.map_err(|error| io_error(format!("failed to open {filename}: {error}")))?;
518518

519519
// Load and return a single private key.
520520
let keys = rustls_pemfile::pkcs8_private_keys(&mut keyfile.as_ref())
521-
.map_err(|_| error("failed to load private key".into()))?;
521+
.map_err(|_| io_error("failed to load private key".to_string()))?;
522+
522523
if keys.len() != 1 {
523-
return Err(error(format!(
524+
return Err(io_error(format!(
524525
"expected a single private key, got {}",
525526
keys.len()
526527
)));
@@ -648,7 +649,7 @@ mod tls {
648649
.with_safe_defaults()
649650
.with_no_client_auth()
650651
.with_single_cert(certs, key)
651-
.map_err(|e| error(format!("{}", e)))?;
652+
.map_err(|error| io_error(error.to_string()))?;
652653
// Configure ALPN to accept HTTP/2, HTTP/1.1, and HTTP/1.0 in that order.
653654
cfg.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec(), b"http/1.0".to_vec()];
654655
Ok(Arc::new(cfg))

quickwit/quickwit-storage/src/bundle_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl fmt::Debug for BundleStorage {
315315
fn unsupported_operation(paths: &[&Path]) -> StorageError {
316316
let msg = "Unsupported operation. BundleStorage only supports async reads";
317317
error!(paths=?paths, msg);
318-
io::Error::new(io::ErrorKind::Other, format!("{msg}: {paths:?}")).into()
318+
io::Error::other(format!("{msg}: {paths:?}")).into()
319319
}
320320

321321
#[cfg(test)]

quickwit/quickwit-storage/src/file_descriptor_cache.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ impl FileDescriptorCache {
138138
let file: File = tokio::task::spawn_blocking(move || std::fs::File::open(split_path))
139139
.await
140140
.map_err(|join_error| {
141-
io::Error::new(
142-
io::ErrorKind::Other,
143-
format!("Failed to open file: {:?}", join_error),
144-
)
141+
io::Error::other(format!("failed to open file: {join_error:?}"))
145142
})??;
146143
let split_file = SplitFile(Arc::new(SplitFileInner {
147144
num_bytes,

quickwit/quickwit-storage/src/object_storage/azure_blob_storage.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use azure_storage::prelude::*;
2727
use azure_storage_blobs::blob::operations::GetBlobResponse;
2828
use azure_storage_blobs::prelude::*;
2929
use bytes::Bytes;
30-
use futures::io::{Error as FutureError, ErrorKind as FutureErrorKind};
30+
use futures::io::Error as FutureError;
3131
use futures::stream::{StreamExt, TryStreamExt};
3232
use md5::Digest;
3333
use once_cell::sync::OnceCell;
@@ -349,7 +349,7 @@ impl Storage for AzureBlobStorage {
349349
let chunk_response = chunk_result.map_err(AzureErrorWrapper::from)?;
350350
let chunk_response_body_stream = chunk_response
351351
.data
352-
.map_err(|err| FutureError::new(FutureErrorKind::Other, err))
352+
.map_err(FutureError::other)
353353
.into_async_read()
354354
.compat();
355355
let mut body_stream_reader = BufReader::new(chunk_response_body_stream);
@@ -448,13 +448,9 @@ impl Storage for AzureBlobStorage {
448448
.range(range)
449449
.into_stream();
450450
let mut bytes_stream = page_stream
451-
.map(|page_res| {
452-
page_res
453-
.map(|page| page.data)
454-
.map_err(|err| FutureError::new(FutureErrorKind::Other, err))
455-
})
451+
.map(|page_res| page_res.map(|page| page.data).map_err(FutureError::other))
456452
.try_flatten()
457-
.map(|e| e.map_err(|err| FutureError::new(FutureErrorKind::Other, err)));
453+
.map(|bytes_res| bytes_res.map_err(FutureError::other));
458454
// Peek into the stream so that any early error can be retried
459455
let first_chunk = bytes_stream.next().await;
460456
let reader: Box<dyn AsyncRead + Send + Unpin> = if let Some(res) = first_chunk {
@@ -552,7 +548,7 @@ async fn download_all(
552548
let chunk_response = chunk_result?;
553549
let chunk_response_body_stream = chunk_response
554550
.data
555-
.map_err(|err| FutureError::new(FutureErrorKind::Other, err))
551+
.map_err(FutureError::other)
556552
.into_async_read()
557553
.compat();
558554
let mut body_stream_reader = BufReader::new(chunk_response_body_stream);

0 commit comments

Comments
 (0)