Skip to content

Commit 611f5ae

Browse files
nootclaude
andauthored
fix manual_let_else clippy errors (#612)
* fix: convert match statements to let...else in nodes.rs Convert manual_let_else warnings to proper let...else syntax in: - restart_node_task: Address::from_str parsing - get_node_logs: Address::from_str parsing and Option unwrapping - get_node_metrics: Address::from_str parsing - ban_node: Address::from_str parsing All changes maintain exact same logic and error handling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix manual_let_else --------- Co-authored-by: Claude <[email protected]>
1 parent 925beaa commit 611f5ae

File tree

20 files changed

+127
-196
lines changed

20 files changed

+127
-196
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ uninlined_format_args = "warn"
5151

5252
[workspace.lints.rust]
5353
unreachable_pub = "warn"
54+
manual_let_else = "warn"

crates/dev-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "dev-utils"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[lints]
7+
workspace = true
8+
69
[dependencies]
710
shared = { workspace = true }
811
tokio = { workspace = true }

crates/discovery/src/api/routes/get_nodes.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ pub(crate) async fn get_nodes_for_pool(
6969

7070
match data.contracts.clone() {
7171
Some(contracts) => {
72-
let pool_info =
73-
match contracts.compute_pool.get_pool_info(pool_contract_id).await {
74-
Ok(info) => info,
75-
Err(_) => {
76-
return HttpResponse::NotFound()
77-
.json(ApiResponse::new(false, "Pool not found"));
78-
}
79-
};
72+
let Ok(pool_info) =
73+
contracts.compute_pool.get_pool_info(pool_contract_id).await
74+
else {
75+
return HttpResponse::NotFound()
76+
.json(ApiResponse::new(false, "Pool not found"));
77+
};
8078
let owner = pool_info.creator;
8179
let manager = pool_info.compute_manager_key;
8280
let address_str = match req.headers().get("x-address") {

crates/discovery/src/api/routes/node.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,14 @@ pub(crate) async fn register_node(
127127
}
128128

129129
if let Some(contracts) = data.contracts.clone() {
130-
let provider_address = match node.provider_address.parse() {
131-
Ok(addr) => addr,
132-
Err(_) => {
133-
return HttpResponse::BadRequest()
134-
.json(ApiResponse::new(false, "Invalid provider address format"));
135-
}
130+
let Ok(provider_address) = node.provider_address.parse() else {
131+
return HttpResponse::BadRequest()
132+
.json(ApiResponse::new(false, "Invalid provider address format"));
136133
};
137134

138-
let node_id = match node.id.parse() {
139-
Ok(id) => id,
140-
Err(_) => {
141-
return HttpResponse::BadRequest()
142-
.json(ApiResponse::new(false, "Invalid node ID format"));
143-
}
135+
let Ok(node_id) = node.id.parse() else {
136+
return HttpResponse::BadRequest()
137+
.json(ApiResponse::new(false, "Invalid node ID format"));
144138
};
145139

146140
if contracts

crates/discovery/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ async fn main() -> Result<()> {
8181

8282
let redis_store = Arc::new(RedisStore::new(&args.redis_url));
8383
let node_store = Arc::new(NodeStore::new(redis_store.as_ref().clone()));
84-
let endpoint = match args.rpc_url.parse() {
85-
Ok(url) => url,
86-
Err(_) => {
87-
return Err(anyhow::anyhow!("invalid RPC URL: {}", args.rpc_url));
88-
}
84+
let Ok(endpoint) = args.rpc_url.parse() else {
85+
return Err(anyhow::anyhow!("invalid RPC URL: {}", args.rpc_url));
8986
};
9087

9188
let provider = RootProvider::new_http(endpoint);

crates/orchestrator/src/api/routes/heartbeat.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ async fn heartbeat(
1818
app_state: Data<AppState>,
1919
) -> HttpResponse {
2020
let task_info = heartbeat.clone();
21-
let node_address = match Address::from_str(&heartbeat.address) {
22-
Ok(address) => address,
23-
Err(_) => {
24-
return HttpResponse::BadRequest().json(json!({
25-
"success": false,
26-
"error": "Invalid node address format"
27-
}));
28-
}
21+
let Ok(node_address) = Address::from_str(&heartbeat.address) else {
22+
return HttpResponse::BadRequest().json(json!({
23+
"success": false,
24+
"error": "Invalid node address format"
25+
}));
2926
};
3027

3128
// Track heartbeat request in metrics

crates/orchestrator/src/api/routes/nodes.rs

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,11 @@ async fn get_nodes(query: Query<NodeQuery>, app_state: Data<AppState>) -> HttpRe
119119
tag = "nodes"
120120
)]
121121
async fn restart_node_task(node_id: web::Path<String>, app_state: Data<AppState>) -> HttpResponse {
122-
let node_address = match Address::from_str(&node_id) {
123-
Ok(address) => address,
124-
Err(_) => {
125-
return HttpResponse::BadRequest().json(json!({
126-
"success": false,
127-
"error": format!("Invalid node address: {}", node_id)
128-
}));
129-
}
122+
let Ok(node_address) = Address::from_str(&node_id) else {
123+
return HttpResponse::BadRequest().json(json!({
124+
"success": false,
125+
"error": format!("Invalid node address: {}", node_id)
126+
}));
130127
};
131128

132129
let node = match app_state
@@ -197,14 +194,11 @@ async fn restart_node_task(node_id: web::Path<String>, app_state: Data<AppState>
197194
tag = "nodes"
198195
)]
199196
async fn get_node_logs(node_id: web::Path<String>, app_state: Data<AppState>) -> HttpResponse {
200-
let node_address = match Address::from_str(&node_id) {
201-
Ok(address) => address,
202-
Err(_) => {
203-
return HttpResponse::BadRequest().json(json!({
204-
"success": false,
205-
"error": format!("Invalid node address: {}", node_id)
206-
}));
207-
}
197+
let Ok(node_address) = Address::from_str(&node_id) else {
198+
return HttpResponse::BadRequest().json(json!({
199+
"success": false,
200+
"error": format!("Invalid node address: {}", node_id)
201+
}));
208202
};
209203

210204
let node = match app_state
@@ -233,23 +227,17 @@ async fn get_node_logs(node_id: web::Path<String>, app_state: Data<AppState>) ->
233227
}));
234228
}
235229

236-
let p2p_id = match node.worker_p2p_id.as_ref() {
237-
Some(id) => id,
238-
None => {
239-
return HttpResponse::BadRequest().json(json!({
240-
"success": false,
241-
"error": "Node does not have worker p2p id"
242-
}));
243-
}
230+
let Some(p2p_id) = node.worker_p2p_id.as_ref() else {
231+
return HttpResponse::BadRequest().json(json!({
232+
"success": false,
233+
"error": "Node does not have worker p2p id"
234+
}));
244235
};
245-
let p2p_addresses = match node.worker_p2p_addresses.as_ref() {
246-
Some(addresses) => addresses,
247-
None => {
248-
return HttpResponse::BadRequest().json(json!({
249-
"success": false,
250-
"error": "Node does not have worker p2p addresses"
251-
}));
252-
}
236+
let Some(p2p_addresses) = node.worker_p2p_addresses.as_ref() else {
237+
return HttpResponse::BadRequest().json(json!({
238+
"success": false,
239+
"error": "Node does not have worker p2p addresses"
240+
}));
253241
};
254242

255243
match app_state
@@ -282,14 +270,11 @@ async fn get_node_logs(node_id: web::Path<String>, app_state: Data<AppState>) ->
282270
tag = "nodes"
283271
)]
284272
async fn get_node_metrics(node_id: web::Path<String>, app_state: Data<AppState>) -> HttpResponse {
285-
let node_address = match Address::from_str(&node_id) {
286-
Ok(address) => address,
287-
Err(_) => {
288-
return HttpResponse::BadRequest().json(json!({
289-
"success": false,
290-
"error": format!("Invalid node address: {}", node_id)
291-
}));
292-
}
273+
let Ok(node_address) = Address::from_str(&node_id) else {
274+
return HttpResponse::BadRequest().json(json!({
275+
"success": false,
276+
"error": format!("Invalid node address: {}", node_id)
277+
}));
293278
};
294279

295280
let metrics = match app_state
@@ -323,14 +308,11 @@ async fn get_node_metrics(node_id: web::Path<String>, app_state: Data<AppState>)
323308
)]
324309
async fn ban_node(node_id: web::Path<String>, app_state: Data<AppState>) -> HttpResponse {
325310
info!("banning node: {node_id}");
326-
let node_address = match Address::from_str(&node_id) {
327-
Ok(address) => address,
328-
Err(_) => {
329-
return HttpResponse::BadRequest().json(json!({
330-
"success": false,
331-
"error": format!("Invalid node address: {}", node_id)
332-
}));
333-
}
311+
let Ok(node_address) = Address::from_str(&node_id) else {
312+
return HttpResponse::BadRequest().json(json!({
313+
"success": false,
314+
"error": format!("Invalid node address: {}", node_id)
315+
}));
334316
};
335317

336318
let node = match app_state

crates/orchestrator/src/plugins/node_groups/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,8 @@ impl NodeGroupsPlugin {
391391
}
392392

393393
pub async fn get_available_configurations(&self) -> Vec<NodeGroupConfiguration> {
394-
let mut conn = match self.store.client.get_multiplexed_async_connection().await {
395-
Ok(conn) => conn,
396-
Err(_) => return vec![],
394+
let Ok(mut conn) = self.store.client.get_multiplexed_async_connection().await else {
395+
return vec![];
397396
};
398397

399398
let available_configs: HashSet<String> = conn

crates/orchestrator/src/store/domains/metrics_store.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ impl MetricsStore {
9292
let mut con = self.redis.client.get_multiplexed_async_connection().await?;
9393
let cleaned_label = self.clean_label(label);
9494

95-
let node_address = match address.parse::<Address>() {
96-
Ok(addr) => addr,
97-
Err(_) => return Ok(false), // Invalid address format
95+
let Ok(node_address) = address.parse::<Address>() else {
96+
return Ok(false);
9897
};
9998

10099
let node_key = format!("{ORCHESTRATOR_NODE_METRICS_STORE}:{node_address}");

crates/shared/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "shared"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[lints]
7+
workspace = true
8+
69
[lib]
710
name = "shared"
811
path = "src/lib.rs"

0 commit comments

Comments
 (0)