Skip to content

Commit

Permalink
Merge pull request #23 from lubinszARM/pr_sdr
Browse files Browse the repository at this point in the history
Fix: Continue iteration after recoverable errors in SdrIter
  • Loading branch information
datdenkikniet authored Jan 6, 2025
2 parents 7b4404c + 5c67bc9 commit 7ce6a6a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

* Fix: Continue iteration after recoverable errors in SdrIter. ([#23])

[#23]: https://github.com/datdenkikniet/ipmi-rs/pull/23

# [0.3.0](https://github.com/datdenkikniet/ipmi-rs/tree/v0.3.0)

* Support for sending bridged IPMB messages for sensors that are not available on the system
Expand Down Expand Up @@ -33,4 +37,4 @@

# [0.2.0](https://github.com/datdenkikniet/ipmi-rs/tree/v0.2.0)

Initial release.
Initial release.
81 changes: 40 additions & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,50 @@ where
type Item = SdrRecord;

fn next(&mut self) -> Option<Self::Item> {
let current_id = self.next_id?;

if current_id.is_last() {
self.next_id.take();
return None;
}

let next_record = self
.ipmi
.send_recv(sdr::GetDeviceSdr::new(None, current_id));

let (value, next_record_id) = match next_record {
Ok(record) => {
let next_record_id = record.next_entry;

(Some(record.record), next_record_id)
}
Err(IpmiError::ParsingFailed {
error: ParseResponseError::Parse((e, next_record_id)),
..
}) => {
log::warn!(
"Recoverable error while parsing SDR record 0x{:04X}: {e:?}",
current_id.value()
);
(None, next_record_id)
}
Err(e) => {
log::error!(
"Unrecoverable error while parsing SDR record 0x{:04X}: {e:?}",
current_id.value()
);
while let Some(current_id) = self.next_id.take() {
if current_id.is_last() {
self.next_id.take();
return None;
}
};

if next_record_id == current_id {
log::error!("Got duplicate SDR record IDs! Stopping iteration.");
self.next_id.take();
return None;
} else {
self.next_id = Some(next_record_id);
let next_record = self
.ipmi
.send_recv(sdr::GetDeviceSdr::new(None, current_id));

match next_record {
Ok(record) => {
let next_record_id = record.next_entry;

if next_record_id == current_id {
log::error!("Got duplicate SDR record IDs! Stopping iteration.");
self.next_id.take();
return None;
}

self.next_id = Some(next_record_id);
return Some(record.record);
}
Err(IpmiError::ParsingFailed {
error: ParseResponseError::Parse((e, next_record_id)),
..
}) => {
log::warn!(
"Recoverable error while parsing SDR record 0x{:04X}: {e:?}. Skipping to next.",
current_id.value()
);
self.next_id = Some(next_record_id);
continue; // skip the current one
}
Err(e) => {
log::error!(
"Unrecoverable error while parsing SDR record 0x{:04X}: {e:?}",
current_id.value()
);
self.next_id.take();
return None;
}
}
}

value
None
}
}

0 comments on commit 7ce6a6a

Please sign in to comment.