fix: improve error handling and code robustness

- state_machine.rs: if-let replaces is_some()+take().unwrap()
- state_machine.rs: expect() replaces unwrap() with invariant docs
- wifi/mod.rs: send_result uses self.id() instead of hardcoded string
This commit is contained in:
2026-03-31 23:25:47 +08:00
parent b570362546
commit d040f51cb2
2 changed files with 4 additions and 4 deletions

View File

@@ -51,8 +51,7 @@ impl StateMachine {
}
// 有待执行的触发器时,跳过 sequence 剩余 step立即切换状态
if self.pending_trigger_target.is_some() {
let target_state = self.pending_trigger_target.take().unwrap();
if let Some(target_state) = self.pending_trigger_target.take() {
self.transition_to_state(&target_state)?;
return Ok(self.current_state != old_state);
}
@@ -273,7 +272,8 @@ impl StateMachine {
}
}
Ok(free_states.last().unwrap().0.clone())
// free_states 非空已由上方 bail! 保证
Ok(free_states.last().expect("free_states is non-empty").0.clone())
}
fn select_weighted_next_state(&self, entries: &[NextStateEntry]) -> Option<String> {

View File

@@ -111,7 +111,7 @@ impl WifiPlugin {
.context("wifi plugin context is not initialized")?;
ctx.tx.send(Envelope {
from: "wifi".to_string(),
from: self.id().to_string(),
to: Destination::Broadcast,
message: Message::WifiResult(payload),
})?;