Skip to content

Commit 89b078e

Browse files
bors[bot]Andful
andauthored
Merge #14
14: Handling errors from closure in function `with_exported` r=posborne a=Andful This change makes sure that `with_exported` handles both possible errors from `closure()` and `self.unexport()` Co-authored-by: Andrea Nardi <[email protected]>
2 parents 1acd9c7 + a5fc88e commit 89b078e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ impl Pwm {
141141
{
142142
self.export()?;
143143
match closure() {
144-
Ok(()) | Err(_) => self.unexport(),
144+
Ok(()) => self.unexport(),
145+
Err(e) => match self.unexport() {
146+
Ok(()) => Err(e),
147+
Err(ue) => Err(error::Error::Unexpected(format!(
148+
"Failed unexporting due to:\n{}\nwhile handling:\n{}",
149+
ue, e
150+
))),
151+
},
145152
}
146153
}
147154

0 commit comments

Comments
 (0)