Improve error handling, ensure robust defaults, and eliminate unsafe unwraps/expectations across modules.
This commit is contained in:
@@ -97,7 +97,7 @@ pub async fn log(
|
||||
impl LogArray {
|
||||
pub fn get(&mut self) -> Vec<LogEntry> {
|
||||
let head: RangedU8<0, MAX_LOG_ARRAY_INDEX> =
|
||||
RangedU8::new(self.head).unwrap_or(RangedU8::new(0).unwrap());
|
||||
RangedU8::new(self.head).unwrap_or(RangedU8::new_saturating(0));
|
||||
|
||||
let mut rv: Vec<LogEntry> = Vec::new();
|
||||
let mut index = head.wrapping_sub(1);
|
||||
@@ -120,7 +120,7 @@ impl LogArray {
|
||||
txt_long: &str,
|
||||
) {
|
||||
let mut head: RangedU8<0, MAX_LOG_ARRAY_INDEX> =
|
||||
RangedU8::new(self.head).unwrap_or(RangedU8::new(0).unwrap());
|
||||
RangedU8::new(self.head).unwrap_or(RangedU8::new_saturating(0));
|
||||
|
||||
let mut txt_short_stack: heapless::String<TXT_SHORT_LENGTH> = heapless::String::new();
|
||||
let mut txt_long_stack: heapless::String<TXT_LONG_LENGTH> = heapless::String::new();
|
||||
@@ -281,6 +281,8 @@ pub enum LogMessage {
|
||||
PumpMissingSensorCurrent,
|
||||
#[strum(serialize = "MPPT Current sensor could not be reached")]
|
||||
MPPTError,
|
||||
#[strum(serialize = "Parsing error reading message")]
|
||||
UnknownMessage,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -301,7 +303,7 @@ impl From<&LogMessage> for MessageTranslation {
|
||||
impl LogMessage {
|
||||
pub fn log_localisation_config() -> Vec<MessageTranslation> {
|
||||
Vec::from_iter((0..LogMessage::len()).map(|i| {
|
||||
let msg_type = LogMessage::from_ordinal(i).unwrap();
|
||||
let msg_type = LogMessage::from_ordinal(i).unwrap_or(LogMessage::UnknownMessage);
|
||||
(&msg_type).into()
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user