From 9c47f830d568e11cf1a47ec550a454c8fa3a6178 Mon Sep 17 00:00:00 2001 From: David Newell Date: Thu, 24 Oct 2024 11:29:11 +0100 Subject: [PATCH] chore: rust linting in CI (#25758) --- .github/workflows/rust.yml | 2 +- rust/cymbal/src/types/mod.rs | 10 +++---- rust/feature-flags/src/flag_matching.rs | 1 + rust/feature-flags/src/request_handler.rs | 2 +- rust/hook-worker/src/worker.rs | 34 ++++++++--------------- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8849e6aefe280..7344b83aef40b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -218,7 +218,7 @@ jobs: - name: Run clippy if: needs.changes.outputs.rust == 'true' - run: cargo clippy -- -D warnings + run: cargo clippy --all-targets --all-features -- -D warnings - name: Run cargo check if: needs.changes.outputs.rust == 'true' diff --git a/rust/cymbal/src/types/mod.rs b/rust/cymbal/src/types/mod.rs index 8fb920ba01256..134a0fcb7420c 100644 --- a/rust/cymbal/src/types/mod.rs +++ b/rust/cymbal/src/types/mod.rs @@ -116,7 +116,7 @@ mod test { Some("https://app-static.eu.posthog.com/static/chunk-PGUQKT6S.js".to_string()) ); assert_eq!(frame.fn_name, "?".to_string()); - assert_eq!(frame.in_app, true); + assert!(frame.in_app); assert_eq!(frame.line, 64); assert_eq!(frame.column, 25112); @@ -126,7 +126,7 @@ mod test { Some("https://app-static.eu.posthog.com/static/chunk-PGUQKT6S.js".to_string()) ); assert_eq!(frame.fn_name, "n.loadForeignModule".to_string()); - assert_eq!(frame.in_app, true); + assert!(frame.in_app); assert_eq!(frame.line, 64); assert_eq!(frame.column, 15003); @@ -142,7 +142,7 @@ mod test { "$exception_list": [] }"#; - let props: Result = serde_json::from_str(&raw); + let props: Result = serde_json::from_str(raw); assert!(props.is_ok()); assert_eq!(props.unwrap().exception_list.len(), 0); @@ -152,7 +152,7 @@ mod test { }] }"#; - let props: Result = serde_json::from_str(&raw); + let props: Result = serde_json::from_str(raw); assert!(props.is_err()); assert_eq!( props.unwrap_err().to_string(), @@ -166,7 +166,7 @@ mod test { }] }"#; - let props: Result = serde_json::from_str(&raw); + let props: Result = serde_json::from_str(raw); assert!(props.is_err()); assert_eq!( props.unwrap_err().to_string(), diff --git a/rust/feature-flags/src/flag_matching.rs b/rust/feature-flags/src/flag_matching.rs index d6449f993d15d..bdcd542f09854 100644 --- a/rust/feature-flags/src/flag_matching.rs +++ b/rust/feature-flags/src/flag_matching.rs @@ -1448,6 +1448,7 @@ mod tests { }, }; + #[allow(clippy::too_many_arguments)] fn create_test_flag( id: Option, team_id: Option, diff --git a/rust/feature-flags/src/request_handler.rs b/rust/feature-flags/src/request_handler.rs index 6c62e7c5ec091..5e0be8faacc59 100644 --- a/rust/feature-flags/src/request_handler.rs +++ b/rust/feature-flags/src/request_handler.rs @@ -213,7 +213,7 @@ fn decode_request(headers: &HeaderMap, body: Bytes) -> Result FlagsResponse { diff --git a/rust/hook-worker/src/worker.rs b/rust/hook-worker/src/worker.rs index c68cdfc3f0cda..1bc97f0395176 100644 --- a/rust/hook-worker/src/worker.rs +++ b/rust/hook-worker/src/worker.rs @@ -489,10 +489,9 @@ async fn process_webhook_job( "timeout while reading response body", )) .await - .map_err(|job_error| { + .inspect_err(|_| { metrics::counter!("webhook_jobs_database_error", &labels) - .increment(1); - job_error + .increment(1) })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1); @@ -523,9 +522,8 @@ async fn process_webhook_job( ("retries", retries.to_string()), ]; - webhook_job.complete().await.map_err(|error| { + webhook_job.complete().await.inspect_err(|_| { metrics::counter!("webhook_jobs_database_error", &labels).increment(1); - error })?; let insert_to_complete_duration = Utc::now() - created_at; @@ -548,9 +546,8 @@ async fn process_webhook_job( webhook_job .fail(WebhookJobError::new_parse(&e.to_string())) .await - .map_err(|job_error| { + .inspect_err(|_| { metrics::counter!("webhook_jobs_database_error", &labels).increment(1); - job_error })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1); @@ -561,9 +558,8 @@ async fn process_webhook_job( webhook_job .fail(WebhookJobError::new_parse(&e)) .await - .map_err(|job_error| { - metrics::counter!("webhook_jobs_database_error", &labels).increment(1); - job_error + .inspect_err(|_| { + metrics::counter!("webhook_jobs_database_error", &labels).increment(1) })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1); @@ -574,9 +570,8 @@ async fn process_webhook_job( webhook_job .fail(WebhookJobError::new_parse(&e.to_string())) .await - .map_err(|job_error| { - metrics::counter!("webhook_jobs_database_error", &labels).increment(1); - job_error + .inspect_err(|_| { + metrics::counter!("webhook_jobs_database_error", &labels).increment(1) })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1); @@ -614,10 +609,9 @@ async fn process_webhook_job( webhook_job .fail(WebhookJobError::from(&error)) .await - .map_err(|job_error| { + .inspect_err(|_| { metrics::counter!("webhook_jobs_database_error", &labels) .increment(1); - job_error })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1); @@ -640,13 +634,9 @@ async fn process_webhook_job( WebhookRequestError::NonRetryableRetryableRequestError { error, response, .. } => { - webhook_job - .fail(webhook_job_error) - .await - .map_err(|job_error| { - metrics::counter!("webhook_jobs_database_error", &labels).increment(1); - job_error - })?; + webhook_job.fail(webhook_job_error).await.inspect_err(|_| { + metrics::counter!("webhook_jobs_database_error", &labels).increment(1); + })?; metrics::counter!("webhook_jobs_failed", &labels).increment(1);