Skip to content

Commit a5fc88e

Browse files
committed
handling errors in closure for function with_exported
Signed-off-by: Andrea Nardi <[email protected]>
1 parent 1acd9c7 commit a5fc88e

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)