WIP: fixing iolist_to_iovec/1 to handle errors when converting list elements to binaries
@@ -20,18 +20,42 @@ pub fn native(process: &Process, iolist_or_binary: Term) -> exception::Result {
vec![iolist_or_binary]
} else {
match iolist_or_binary.to_typed_term().unwrap() {
- TypedTerm::List(boxed_cons) => boxed_cons
+ TypedTerm::List(boxed_cons) => {
+ let mut l: Vec<Term> = Vec::new();
+
+ let res = boxed_cons
.into_iter()
- .map(|item| {
- let term: Term = item.unwrap();
+ .try_for_each(|item| {
+ let term: Term = match item {
+ Ok(term) => term,
+ bad => {
+ return Err(bad);
+ }
+ };
if term.is_binary() {
- term
+ l.push(term);
+ Ok(())
} else {
- otp::erlang::list_to_binary_1::native(process, term).unwrap()
+ 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(())
+ }
+ }
+ }
+ });
+
+ if res.is_ok() {
+ l
+ } else {
+ return Err(badarg!().into());
+ }
}
- })
- .collect(),
_ => return Err(badarg!().into()),
}
};
