Fix iteration in iolist_to_iovec/1 to handle errors
@@ -21,41 +21,26 @@ pub fn native(process: &Process, iolist_or_binary: Term) -> exception::Result {
} else {
match iolist_or_binary.to_typed_term().unwrap() {
TypedTerm::List(boxed_cons) => {
- let mut l: Vec<Term> = Vec::new();
+ let mut binaries: Vec<Term> = Vec::new();
- let res = boxed_cons
- .into_iter()
- .try_for_each(|item| {
+ for item in boxed_cons.into_iter() {
let term: Term = match item {
Ok(term) => term,
- bad => {
- return Err(bad);
- }
+ _ => return Err(badarg!().into())
};
if term.is_binary() {
- l.push(term);
- Ok(())
+ binaries.push(term);
} else {
match otp::erlang::list_to_binary_1::native(process, term) {
- Ok(term) => {
- l.push(term);
- Ok(())
- },
- _ => {
- // HACK: this satisfies the compiler, but is incorrect, so the test fails
- Ok(())
+ Ok(term) => binaries.push(term),
+ _ => return Err(badarg!().into())
}
}
}
- });
- if res.is_ok() {
- l
- } else {
- return Err(badarg!().into());
- }
- }
+ binaries
+ },
_ => return Err(badarg!().into()),
}
};
