Skip to content

Commit

Permalink
chore: rust linting in CI (#25758)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Oct 24, 2024
1 parent 2a0a953 commit 9c47f83
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions rust/cymbal/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -142,7 +142,7 @@ mod test {
"$exception_list": []
}"#;

let props: Result<ErrProps, Error> = serde_json::from_str(&raw);
let props: Result<ErrProps, Error> = serde_json::from_str(raw);
assert!(props.is_ok());
assert_eq!(props.unwrap().exception_list.len(), 0);

Expand All @@ -152,7 +152,7 @@ mod test {
}]
}"#;

let props: Result<ErrProps, Error> = serde_json::from_str(&raw);
let props: Result<ErrProps, Error> = serde_json::from_str(raw);
assert!(props.is_err());
assert_eq!(
props.unwrap_err().to_string(),
Expand All @@ -166,7 +166,7 @@ mod test {
}]
}"#;

let props: Result<ErrProps, Error> = serde_json::from_str(&raw);
let props: Result<ErrProps, Error> = serde_json::from_str(raw);
assert!(props.is_err());
assert_eq!(
props.unwrap_err().to_string(),
Expand Down
1 change: 1 addition & 0 deletions rust/feature-flags/src/flag_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ mod tests {
},
};

#[allow(clippy::too_many_arguments)]
fn create_test_flag(
id: Option<i32>,
team_id: Option<TeamId>,
Expand Down
2 changes: 1 addition & 1 deletion rust/feature-flags/src/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn decode_request(headers: &HeaderMap, body: Bytes) -> Result<FlagRequest, FlagE
/// Evaluate feature flags for a given distinct_id
/// - Returns a map of feature flag keys to their values
/// - If an error occurs while evaluating a flag, we'll set `error_while_computing_flags` to true be logged,
/// and that flag will be omitted from the result (we will still attempt to evaluate other flags)
/// and that flag will be omitted from the result (we will still attempt to evaluate other flags)
// TODO: it could be a cool idea to store the errors as a tuple instead of top-level, so that users can see
// which flags failed to evaluate
pub async fn evaluate_feature_flags(context: FeatureFlagEvaluationContext) -> FlagsResponse {
Expand Down
34 changes: 12 additions & 22 deletions rust/hook-worker/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,9 @@ async fn process_webhook_job<W: WebhookJob>(
"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);
Expand Down Expand Up @@ -523,9 +522,8 @@ async fn process_webhook_job<W: WebhookJob>(
("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;
Expand All @@ -548,9 +546,8 @@ async fn process_webhook_job<W: WebhookJob>(
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);
Expand All @@ -561,9 +558,8 @@ async fn process_webhook_job<W: WebhookJob>(
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);
Expand All @@ -574,9 +570,8 @@ async fn process_webhook_job<W: WebhookJob>(
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);
Expand Down Expand Up @@ -614,10 +609,9 @@ async fn process_webhook_job<W: WebhookJob>(
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);
Expand All @@ -640,13 +634,9 @@ async fn process_webhook_job<W: WebhookJob>(
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);

Expand Down

0 comments on commit 9c47f83

Please sign in to comment.